item (Options, Select)

item method

Retrieves a select object or an object from an options collection.


object.item(name, index)


name [in]

Type: Variant

Variant of type Integer or String that specifies the object or collection to retrieve. If this parameter is an integer, it is the zero-based index of the object. If this parameter is a string, all objects with matching name or id properties are retrieved, and a collection is returned if more than one match is made.

index [in, optional]

Type: Variant

Variant of type Integer that specifies the zero-based index of the object to retrieve when a collection is returned.

Return value

Type: Object

Returns an object or a collection of objects if successful, or null otherwise.

Standards information

There are no standards that apply here.


Note   This method indexes collections by the name or id property of the object; this is a known standards-compliance issue. For interoperability with other browsers, do not reference an object by name using this method.


The following example uses the item method to retrieve each object in the options collection of a select object.

  <option value ="ford">Ford</option>
  <option value ="chev">Chevrolet</option>
  <option value ="bmw">BMW</option>
  <option value ="lexus">Lexus</option>
<script type="text/jscript">
  window.onload = function() {
    var oSelect = document.getElementsByTagName("SELECT")[0];
    var oColl = oSelect.options;
    var sTxtNode = new Array();
    for (i=0; i<oColl.length; i++) {     
      sTxtNode[i] = oColl.item(i).innerHTML;                
    console.log("There are " + oColl.length + " options in the select object:" + "\n" +
      sTxtNode[0] + "\n" + sTxtNode[1] + "\n" + sTxtNode[2] + "\n" + sTxtNode[3]);  

See also




© 2017 Microsoft