Javascript examples for DOM HTML Element:Select
The remove() method removes an option from a drop-down list.
Parameter | Description |
---|---|
index | Required. index of the option to remove. Index starts at 0 |
No return value
The following code shows how to Remove the selected option from the drop-down list:
<!DOCTYPE html> <html> <body> <form> <select id="mySelect" size="4"> <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> </select>/*from ww w . j a v a 2 s. co m*/ </form> <br> <button onclick="myFunction()">Remove last option</button> <script> function myFunction() { var x = document.getElementById("mySelect"); if (x.length > 0) { x.remove(x.length-1); } } </script> </body> </html>