Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Way of adding items in Drop Down List or List Box using Javascript

0.00/5 (No votes)
6 Jun 2010 1  
Hi,    function AddItem(Text,Value)    {        // Create an Option object                var opt =

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Hi,

<script type="text/javascript">

    function AddItem(Text,Value)

    {

        // Create an Option object        

        var opt = document.createElement("option");

      // Add an Option object to Drop Down/List Box

        document.getElementById("DropDownList").options.add(opt);

        // Assign text and value to Option object

        opt.text = Text;

        opt.value = Value;

    }

<script />

     You can use this function in for loop to add more than one item. 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here