Saturday, November 3, 2012

how to add items to dropdownlist in javascript dynamically

Introduction


In this article, i am going to show the  dynamic addition of an item in a HTML  DropDownList control
USING JAVASCRIPT

 

<select id="ctype" style="width:206px"><option>Select</option></select>

 

<script type="text/javascript" >

function addOption(selectbox, text, value) {

        var optn = document.createElement("OPTION");

        optn.text = text;

        optn.value = value;

        selectbox.options.add(optn);

    }

 

 

 

for (var i = 0; i < 100; ++i) {

 

       addOption(ctype, "YOUR TEXT","YOUR VALUE");

        }

 

</script>

No comments:

Post a Comment