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); }) 

http://jsfiddle.net/yzm7a/3/

although 1 sees there remains problem of selected value in second dropdown not changing


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -