javascript - filtering drop down menu using value -
is possible in javascript filter drop down menu based on field menu using value attribute?
i mean, have following code, built django-framework :
<p><label for="id_country">country :</label> <select id="id_region" name="region"> <option value="" selected="selected">---------</option> <option value="1">usa</option> <option value="2">france</option> </select></p> <p><label for="id_region">region :</label> <select id="id_city" name="city"> <option value="" selected="selected">---------</option> <option value="1">california</option> <option value="2">new-york</option> <option value="3">oregon</option> <option value="4">tenessee</option> <option value="5">paris</option> <option value="6">bretagne</option> ...
and have filter value using number of value want properly. can write like:
if(id_country == usa) then: id_region_value between 1 , 4 if(id_country == france) then: id_region_value between 5 , 6
you need each second select
$("#id_region").change(function(){ $("#id_city option[value!='']").hide(); if($(this).val()==1){ $("#id_city option").each(function(){ if($(this).val() >=1 && 4>=$(this).val()){ $(this).show(); } }); } if($(this).val()==2){ $("#id_city option").each(function(){ if($(this).val() >=5 && 6>=$(this).val()){ $(this).show(); } }); } });
Comments
Post a Comment