Visual InterDev

addItem Method

See Also      Applies To

Adds an item to a Listbox or OptionGroup object.

Syntax

object.addItem(strItem, [strValue], [nIndex]);

Parameters

object

A Listbox or OptionGroup script object.

strItem

Specifies the display text of the item.

strValue

Specifies a string for the VALUE attribute of the item.

nIndex

An integer that specifies the item's position within the list.

Remarks

If the strValue parameter is not supplied, the strItem parameter will be used as strValue.

If the nIndex parameter is not supplied, the item is added to the end of the list.

The addItem method is not supported by an object whose RowSource is bound to a Recordset object.

Example

The following script uses the window onload event in DHTML to fill a list box.

function window_onload() 
{
   for ( i=0; i<5; i++)
   {
      myListbox.addItem("Item " + i );   
   }
   myListbox.selectedIndex = 3;      // select the 4th item
}