Filter child select box value from parent using Jquery -
i have 2 selection boxes,one contains country names , contains state names of countries.
<select id="parent"> <option value="country1">country1</option> <option value="country2">country2</option> <option value="country3">country3</option> </select> <select id="child"> <option value="country1 state1">country1 state1</option> <option value="country1 state2">country1 state2</option> <option value="country2 state1">country2 state1</option> <option value="country2 state2">country2 state2</option> <option value="country3 state1">country3 state1</option> </select>
then if select country1 parent selection box, state selection box has need show states of country1 alone , remove other states it.
i need find child values partial match , verify parent value..
$(document).ready(function(){ $('#parent').change(function(){ var filter = $(this).val(); $('option').each(function(){ if ($('option:contains("' + var1 '")') == filter) { $(this).show(); } else { $(this).hide(); } var var1= $('#child').val(filter); }) }) })
please me on this.
$("#parent").change(function(){ var filter = $(this).val(); $("#a").append('a'); $('select#child option').each(function(){ $("#a").append('a'); if ( $(this).val().substring(0,8) == filter) { $(this).show(); } else { $(this).hide(); } }); var var1= $('#child').val(filter); })
although 1 sees there remains problem of selected value in second dropdown not changing
Comments
Post a Comment