Archive for August 15, 2007

How to Remove an Option from a Dropdown Select Box with JavaScript

Posted in JavaScript on August 15, 2007 by Joey

To remove an option from a dropdown select box with JavaScript, use the JavaScript remove method. Pass it the index of the option that should be removed. The index is 0-based, so to remove the first item in the select list pass 0, to remove the second pass 1 and so forth.

If this is the select list:

<select name='dropdown' id='dropdown'>
  <option value='1'>1</option>
  <option value='2'>2</option>
  <option value='3'>3</option>
</select>

The second option can be removed as follows:

document.getElementById('dropdown').remove(1);

Related articles:
How to Remove All Options from a Dropdown Select Box with JavaScript