javascript - how to apply if statement for form's <select> relation -


in real, want make this: have 2 select field options in form, , want: if in first select option (for example id="2"), second select filed changes auto pay attention first field selected option.

<form> <select>    <option id="1"></option>    <option id="2"></option>    <option id="3"></option> </select>    #in here if select option 1 id show select field 1th id: <select id="1th">     #options here... </select>     #if select option 2 id show select field 2th id: <select id="2th">     #options here... </select>     #if select option 3 id show select field 3th id: <select id="3th">     #options here... </select> </form> 

(change form other fields changing form select field).

if can make jquery. better even. thanks.

using jquery , value of first select element, easy create.

<select id="first-select">    <option value="1"></option>    <option value="2"></option>    <option value="3"></option> </select> 

note: don't use id's did, use values instead. each subselect, add id , class, use show , hide right selects.

<select id="select-1" class="hideifnotselected">     #options here </select> 

then use jquery.

<script type="text/javascript">  $(document).ready(function(){      $("#first-select").on('change', function(event) {          var selected = this.val();           $(".hideifnotselected").hide(); //hide selects          $("#select-"+ selected).show(); //show selected select.     });  });  </script> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -