I want to give 2 option for 5th subjects depending on stream choice. Means if user select Commerce then he/she must able to select any 1 subject from drop down either IP or Other same for other streams. –
<!-- 1st select block will look like this -->
<td>Stream :
<select name="stream">
<option value="1">Commerce</option>
<option value="2">Humanities</option>
<option value="3">Sci[PCM]</option>
<option value="4">Sci[PCB]</option>
</select>
</td>
<!-- On Selecting the stream 5th subject will populated automatically accoring ti their respective stream which is like this -->
<td>5th Subjects :
<select name="5thsub">
<option value="1">IP</option>
<option value="1">OTHER</option>
<option value="2">Hindi</option>
<option value="2">IP</option>
<option value="3">CS</option>
<option value="3">IP</option>
<option value="4">Math</option>
<option value="4">Hindi</option>
</select>
</td>
<script>
$(document).ready(function(){
var secondSelect = $("select[name='core']");
var thirdSelect = $("select[name='5thsub']");
var secondOptions = secondSelect.children('option');
var thirdOptions = thirdSelect.children('option');
$("select[name='stream']").change(function(){
var selectedIndex = this.selectedIndex;
secondOptions.filter(function(i){ return i == selectedIndex})
.appendTo(secondSelect.empty());
thirdOptions.filter(function(i){ return i == selectedIndex})
.appendTo(thirdSelect.empty());
}).change();
});
</script>
I am trying to achive the result by using this code but I am getting only 1 item in 2nd drop down and according to the index number of item of 1st drop down. Means if I select Commerce I get IP is 2nd drop down, if I select Humanity I get Other.
Where as I should get IP and Other for Commerce from where I can select any 1 of the subject.