Home / ASP.NET Wiki / Javascript / Way of adding items in Drop Down List or List Box using Javascript

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

 Rate It (0)

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. 

Revision number 1, Sunday, June 06, 2010 8:56:55 AM by raja.s
This is not the most up to date version of this article. The most recent version can be found here.

Comments

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. abiruban (1)