Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two drop down lists
HTML
<select id="dropdown1">
 <option value="1">Item1</option>
 <option value="2">Item2</option>
 <option value="3">Item3</option>
<option value="4">Item4</option>
<option value="5">Item5</option>
</select>

<select id="dropdown2">
 <option value="6">Item1</option>
 <option value="7">Item2</option>
 <option value="8">Item3</option>

</select>


When I select 1 in the first drop down second drop down should show 6.
And if I select 2, 7 should show in second and 8 for all the others. I want this to be done in JQUERY. Can you please help me.
Thanks in advance.
Posted
Comments
ZurdoDev 20-Apr-15 10:14am    
Just google how onchange jquery dropdown and you should get it.

This is pretty easy : Just Listen on the change event on SELECT and then change the value of other drop down as below.


C#
$(document).ready(function(){

    $("#dropdown1").on("change",function(){

      var other= $("#dropdown2");

       var value=$(this).val();

        switch (value) {
            case "1":  other.val("6"); console.log('hi1',other); break;
            case "2" : other.val("7");break;
            case "3" : break;
            case "4" : break;
            default : console.log('hi');;
        }
 
Share this answer
 
v2
Comments
Deepak Kanswal Sharma 20-Apr-15 23:31pm    
What if multiple data is to be selected in second dropdown??
Since they are based on same selected indices, try this demo[^].
 
Share this answer
 
Enum dropdown1
{
One,
Two
};
Enum dropdown2
{four,five};

Design two listboxes
Listbox1 and listbox2
In the listbox_leave event(object obj,Eventargs e)
{
If(listbox1.SelectedItems==dropdown1.one.Tostring())
{
Listbox2.items.add(dropdown2.four.ToString());
//similarly add how many elements u want
}
Else
{listbox2.items.add(dropdown2.five.ToString());
Dropdown2.show();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900