For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

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

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip