jquery - Select concatenated: if selected option have value 1, show another select -


i've problem. want show select if choose yes in option, have value = 1

    <select id="select_one">        <option value="1">yes</option>        <option value="0">no</option>     </select>      <select id="select_yes" style="display:none">         <option>yes</option>         <option>no</option>     </select> 

this jquery code:

jquery("#select_one").change(function() {     if(jquery("#select_one option:selected").val() == 1){         jquery("#select_yes").css('display','block');     }  }); 

i tryed change css class, doesn't work.

try:

$(document).ready(function () {     $('#select_one').on('change', function() {         if ($('#select_one option:selected').val() == 1) {             $('#select_yes').show();         } else {             $('#select_yes').hide();         }     }) }); 

demo: https://jsfiddle.net/tvvef0nd/

or

shorter way:

$(document).ready(function () {     $('#select_one').on('change', function() {         $('#select_yes').toggle($('#select_one option:selected').val() == 1);     }); }); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -