Skip to main content

Posts

Showing posts from January, 2011

Adding another option to Dropdown box using JavaScript

Below are the steps for adding an option to the dropdown box using JavaScript. ·   Create a Option element using JavaScript       var opt = document.createElement("option"); ·    Add Option object to dropdown box              document.getElementById("test").options.add(opt); ·     Assign value and text to the Option object just added     opt.text = "New";     opt.value = "0";     ·       Insert this Option object just created at top position inside dropdown. This step is optional, if this step is not performed the Option object will added to dropdown as the last item.           document.getElementById("test").insertBefore(opt, document.getElementById("test").firstChild);   ·      To make the Option object as default when th...

Returning selected value from Dropdown Box using JavaScript

Below is the example for returning value of the selected item in a Dropdown box: HTML Dropdown control or element with the id “test”              <select id="test" onchange="getVal();">                   <option value="1">1</option>                   <option value="2">2</option>                   <option value="3">3</option>            </select> JavaScript function for getting the selected value from dropdown: ·   First get the selected index from the dropdown and store it in a variable.        var ddIndex = document.getElementById("test...