JAVASCRIPT - HOW TO Add Option to Select - Javascript Source Code

JAVASCRIPT - HOW TO Add an Option or List Item to a HTML Select Element in Javascript with One Simple Line of Javascript Code

Home Short:

Below is a simple Javascript function you can save and re-use to much more easily add a new list item to a select element, which is actually referred to as a listbox in regular computer programming.

For example, in Visual Basic 5 and Visual Basic 6, you can very easily add a new item to a listbox with this simple line of code listbox.additem "string to add to listbox".

Store and save the below Javascript function and then you can add items to a select element just as easily with this simple line of code assuming the id of the select element is selAnimals and the text you want to add is dog: selectListAdd ('selAnimals', 'dog');

S
H
A
R
E