I am having two dropdowns in my page.On change of my first dropdown i need to populate the array values into another dropdown.On every change it should change the values.Can u please help on this
Asked
Active
Viewed 1,813 times
0
-
See this may be help you http://stackoverflow.com/questions/9170453/display-dropdown-values-based-on-previous-dropdown – Hkachhia Dec 07 '12 at 09:12
1 Answers
1
try following :
$("#dropDown1").change(function(){
var dp2Values = [1,2,3,4,5];
$("option",$(this)).remove();
$.each(dp2Values ,function(a,b){
$("<option></option>").text(b).appendTo($("#dropDown2"));
});
});
if you'r data would depend on selected index use this to retrive index :
$("#dropDown1").change(function(){
var $index = $("option:selected",$(this));
});

Behnam Esmaili
- 5,835
- 6
- 32
- 63
-
Thanks very much.But when i am changing second time the values are coming twice....I want only once on every change...can u please help on this – user1799494 Dec 07 '12 at 09:29
-
updated the code.added this line : $("option",$(this)).remove(); – Behnam Esmaili Dec 07 '12 at 09:32
-
1@user1799494 it is a good habit to accept the answer if it solve your problem! – Behnam Esmaili Dec 07 '12 at 09:43