Add Item to DropDownList Dynamically in Javascript

The following javascript function demonstrates how to add new items to Combobox in HTML. The solution utilizes appendChild (select) and createElement (document) functions accordingly. Works both in Internet Explorer and Firefox.

       <script type="text/javascript">
           function add() {
               var newOpt = mySel.appendChild(document.createElement('option'));
               newOpt.text = "New Item";

       <elect id="mySel">
<option>item 1
<input type="button" value="Add" onclick="add();">

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads