Fill and Empty SELECT box in jquery
If you fill combobox from database in html and ajax jquery.
ajax jquery transfer datas from database and
you needed to put those datas into select box. Before this you need to clear
existing datas from select combo box then you will use “empty()” and “apped()”
to use fill the data. Use listed below codes to achieve that.
====================================================
<script src="jquery-1.6.3.min.js" language="javascript" type="text/javascript"></script>
<select name="myNum" Id="myNum" >
<option value="0"><-- Select --></option>
</select>
<br/>
<input type="button" id="myadd" name="myadd" value="Add"/>
<script>
$(function(){
$("#myadd").click(function() {
$('#myNum').empty();
var i;
for(i=0;i<=10;i++) {
$('#myNum').append('<option value="' + i + '">' +i + '</option>');
}
});
});
</script>
<script src="jquery-1.6.3.min.js" language="javascript" type="text/javascript"></script>
<select name="myNum" Id="myNum" >
<option value="0"><-- Select --></option>
</select>
<br/>
<input type="button" id="myadd" name="myadd" value="Add"/>
<script>
$(function(){
$("#myadd").click(function() {
$('#myNum').empty();
var i;
for(i=0;i<=10;i++) {
$('#myNum').append('<option value="' + i + '">' +i + '</option>');
}
});
});
</script>
0 comments:
Post a Comment