Select Object
The options collection returns a collection of all the options in a dropdown list.
Note: There will be one array element for each <option> tag - starting at 0.
| Property | Description |
|---|---|
| length | Returns the number of option elements in the collection |
| selectedIndex | Sets or returns the index of the selected option in a select object (starts at 0) |
| Method | Description |
|---|---|
| [index] | An integer that specifies the element to retrieve (starts at 0) |
| [add(element[,index])] | Adds an option element into the collection at the specified index. If no index is specified, it inserts the option element at the end of the collection |
| item(index) | Returns the element from the collection with the specified index |
| namedItem(name) | Returns the element from the collection with the specified name (name or id attribute) |
| remove(index) | Removes the element with the specified index from the collection |
![]()
The options collection is supported in all major browsers.
Loop through all options in the dropdown list, and output the text:
Change the items in a dropdown list depending on the selected option in another dropdown list
Select Object
Your message has been sent to W3Schools.