Hi. I have a select box with the id=1. I need a solution for: when changing the select box with the id=1 to appear another select box with the id=2 and when changing the select box with the id=2 to appear another with the id=3, and so on.
I have writen a code, and I do not understand why it does not work the way I need. It works only when I change the first select box. Can somebody advise, please.
<select id="1" name="1">
<option value="Value 1">Text 1</option>
<option value="Value 2">Text 2</option>
<option value="Value 3">Text 3</option>
<option value="Value 4">Text 4</option>
<option value="Value 5">Text 5</option>
</select>
<div id="newselect"> </div>
<script type="text/javascript">
$(document).ready(function(){
var i = 1;
$('#' + i).change(function(){
i++;
alert(i);
var s = $('<select id="' + i + '" name="' + i + '" />');
$("<option />", {'value':'Value 1', 'text':'Text 1'}).appendTo(s);
$("<option />", {'value':'Value 2', 'text':'Text 2'}).appendTo(s);
$("<option />", {'value':'Value 3', 'text':'Text 3'}).appendTo(s);
$("<option />", {'value':'Value 4', 'text':'Text 4'}).appendTo(s);
$("<option />", {'value':'Value 5', 'text':'Text 5'}).appendTo(s);
s.appendTo("#newselect");
});
})
</script>