<input id="studentnoofinst" type="text" size="20" value=""/>
<select id="studentinst" size="6">
<option value="1">First Installment</option>
<option value="2">Second Installment</option>
<option value="3">Third Installment</option>
<option value="4">Fourth Installment</option>
<option value="5">Fifth Installment</option>
<option value="6">Sixth Installment</option>
</select>
Jquery
$("#studentnoofinst").keyup(function() {
//$("select option[value='fb']").prop("selected",true);
alert("going to change");
$leap=0;
$leap=($('#studentnoofinst').val());
if($leap!=''){
for(i=$leap;i<=6;i++) {// displaying the no of installments
if(i!=$leap){
$('#studentinst option[value='+i+']').remove();
}
}
}
});
Hi, as shown in the code above i am able to remove the selected row, My question is that i am not able to add the selected option back,How to add the selected row back
P.S:once if enter 4 the last 2 rows are deleted and later if enter 5 only the first 4 rows are display and the 5 row is vomitted.. but it need it
if first time the input =4
ouptut:
<option value="1">First Installment</option>
<option value="2">Second Installment</option>
<option value="3">Third Installment</option>
<option value="4">Fourth Installment</option>
if second time the input =5
ouptut:
<option value="1">First Installment</option>
<option value="2">Second Installment</option>
<option value="3">Third Installment</option>
<option value="4">Fourth Installment</option>
<option value="5">Fifth Installment</option>//vomitted but i need this? add
Live example here: http://jsfiddle.net/PQ7GF/30/
EDIT – merged the changes made by soul:
you could save the options in a variable and add them back:
fiddle here: http://jsfiddle.net/PQ7GF/49/