Anatoly Lubarsky Logo
MSSQL, .NET, Design. Life and Music

Javascript Tip: Add Item to Combobox Dynamically

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.


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

< body>
< select id="mySel">
< option>item 1
< /select>
< input type="button" value="Add" onclick="add();">
< /body>
< /html>

Enjoy :)


Related Posts:

Tuesday, June 05, 2007 4:04 AM

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)