How to Add an Option to a Dropdown Select Box with JavaScript

To add an option to a dropdown select box with JavaScript, first create the option that will be added. Then add the option, as shown in the following example.

If this is the select list:

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

This JavaScript will add an option at the end of the list with a value of 3 and a label of 3:

var objDropdown = document.getElementById('dropdown');
var objOption = new Option('3','3');
document.write(objOption.value);
objDropdown.options[objDropdown.length] = objOption;

The two arguments to the Option method are text and value. Text is what shows in the dropdown box and is the first argument. Value is what is sent with the form submission and is the second argument. Note also that the length of the dropdown box is used to put the new option at the end of the list. A value could be hard-coded here, if desired.

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

3 Responses to “How to Add an Option to a Dropdown Select Box with JavaScript”

  1. A Big Fan Says:

    Hello JoeyJavaScript,

    We love your articles. Would you please post more?

    Kind Regards,
    A Big Fan

  2. Thanks for your interest. I plan to post additional articles in the near future.

  3. manoj d Says:

    How can i calculate (addtion, multiplication, division) two diffrent selection box values on web page without any database
    and show result of calculation in input box. all values will be numeric.

Leave a Reply