Option index attribute

Definition and Usage

index Sets or returns the index position of the option in the dropdown list.

Indexes (indices) start from 0.

See also:

HTML Reference Manual:Tafuta <option> ya HTML

Instance

Example 1

Show the index and text of the selected option in the dropdown list:

var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementById("mySelect").options;
alert("Index: " + y[x].index + " is " + y[x].text);

Kufaa kwa uwanza

Example 2

Show all text and index of options in the dropdown 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;
}

Kufaa kwa uwanza

Inayofanywa kwa

Kutumia index ya muundo:

optionObject.index

Mtuwa kwa index ya muundo:

optionObject.index = integer

Muundo wa kiwango

Wakati Utafiti
integer Inashughulikia indidi ya kitambaa cha kizito cha chagua.

Vitambaa vya teknolojia

Wakati: Wakati, inaangazia indidi ya kitambaa cha kizito cha chagua. Indidi inatufika kuanzia 0.

Muunaji wa kifungu

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Msaada Msaada Msaada Msaada Msaada