For smart Primates & ROBOTS (oh and ALIENS ).

Wednesday, May 07, 2014

Fill and Empty SELECT box in jquery

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>
Share:

0 comments:

Post a Comment

Featured Post

Core Web Vitals Assessment showing LCP 10.6s while google pagespeed report showing LCP 3.5s why?

Core Web Vitals Assessment showing LCP 10.6s while google pagespeed report showing LCP 3.5s why? So, you can face this situation while...

Ads Inside Post

Powered by Blogger.

Arsip