Welcome Guest, Not a member yet? Register   Sign In
dropdown
#1

[eluser]Unknown[/eluser]
how to create dropdown to filter other dropdow

example

dropdown1 :
<select name='datatype'>
<option='char'>char</option>
<option='int'>int</option>
<option='decimal'>decimal</option>
</select>

dropdown2 :
<select name='contenttype'>
<option='char'>abc</option>
<option='char'>DEF</option>
<option='int'>123</option>
<option='int'>456</option>
<option='decimal'>1.23</option>
<option='decimal'>4.56</option>
</select>
#2

[eluser]xwero[/eluser]
I guess the html should be
Code:
dropdown1 :
<select name=’datatype’ id="datatype">
<option value=’char’>char</option>
<option value=’int’>int</option>
<option value=’decimal’>decimal</option>
</select>

dropdown2 :
<select name=’contenttype’ id="contenttype">
<option class=’char’>abc</option>
<option class=’char’>DEF</option>
<option class=’int’>123</option>
<option class=’int’>456</option>
<option class=’decimal’>1.23</option>
<option class=’decimal’>4.56</option>
</select>
To do this with jQuery you can use following code
Code:
$(function(){
   $('#datatype').change(function(){ // do something when an option is picked from the select
     var type = $(':selected',this).val(); // retrieve the value of the option
     $('#contenttype option[class!="'+type+'"]').hide();
     // hide all options that don't have the same class name as the selected option in the datatype select
   });
});
I used a class for the datacontent options because you are going to want to retrieve the value of the option.
It's not tested but if it doesn't work it gives you a good idea on how you can do it.




Theme © iAndrew 2016 - Forum software by © MyBB