HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Option Object : Display the index and text of the selected option in a drop-down list
The index property sets or returns the index position of an option in a drop-down list.
The index starts at 0.
Property | |||||
---|---|---|---|---|---|
index | Yes | Yes | Yes | Yes | Yes |
Return the index property:
Set the index property:
Value | Description |
---|---|
integer | Specifies the index position of the option within a drop-down list |
Return Value: | A Number, representing the index position of the option within a drop-down list. The index starts at 0. |
---|
Display the text and index of all options in a drop-down list:
var x = document.getElementById("mySelect");
var txt = "All options: ";
var i;
for (i = 0; i < x.length; i++) {
txt = txt + "\n" + x.options[i].text + " has index: " + x.options[i].index;
}
❮ Option Object