Friday, April 8, 2011

adding items to dropdown and clear items using javascript

<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 />

clear items in dropdown

  var theDropDown = document.getElementById("testddl") 
         var numberOfOptions = theDropDown.options.length
         for (i = 0; i < numberOfOptions; i++) {
           //Note: Always remove(0) and NOT remove(i)
             theDropDown.remove(0);
            }


http://chiragrdarji.wordpress.com/2007/06/06/add-items-in-drop-down-list-or-list-box-using-javascript/

No comments:

Post a Comment