Wednesday 8 January 2014

Add items and removing all option of dropdown box in javascript

Add items and removing all option of dropdown box in javascript


How to add items in dropdown 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 />


Removing all option of dropdown box in JavaScript

document.getElementById('id').options.length = 0;

No comments:

Post a Comment