Note : The Options Collection is supported by both Netscape and Internet Explorer.
The Options collection is an ordered, indexed array, containing a reference to every
<OPTION> element in a given
<SELECT> element. A separate options collection is available for each different
<SELECT> element in the document and the options collection can only be referenced through a reference to a valid
<SELECT> element object.
Option Objects would normally be retrieved by their index in the options collection. I.e.:
VALUE attribute of the second
<OPTION> element in the
<SELECT> element referenced by
<SELECT>reference. For example, consider the following:
<OPTION VALUE="BuryLove" ID="BLove">Bury Your Love Like Treasure
<OPTION VALUE="JacketHangs" ID="JHangs">Jacket Hangs
<OPTION VALUE="LoverAndConfidante" ID="Lover">Lover And Confidante
Calling the following in a script function:
A string value can be used however, as long as that string is a valid identifier (
ID attribute value) for an
<OPTION> element in the referenced
<SELECT> element in the document.
would return the
Lover And Confidante - the displayed text for the
<OPTION> element whose
ID attribute is 'Lover'.
length property returns the number of options in the collection. Note that the
length count starts at 1, not 0 as the options collection index does. Therefore, the
length property may return a value of 5, but to access the 3rd option in a
<SELECT>, you'd need to use
add method can be used to add option objects to the collection. Note that the new
<OPTION> element must first be created by using the
createElement method of the Document Object.
add method takes the single argument of
index which specifies where in the options collection the new element is to be placed. If no
index argument is specified, the new option object is appended to the end of the collection.
item method retrieves single items, or sub-collections from an areas collection. It accepts the following arguments:
index is a number, then the method returns a reference to the
<OPTION> at that position in the options collections index. I.e.
strTag be the value of the
VALUE attribute of the
<OPTION>. As you can see, this is effectively the long-hand version of using
index property is a string value, then the
item method returns a sub-collection, containing a reference to every option object in the select object that has its
ID attribute set to the string contained in the
index argument. To retrieve certain element objects from this sub-collection, the
sub-index argument must be used.
remove method can be used to remove an option object from a select object. For example, using the
<OPTION> set from above, using:
would remove the second
<OPTION> choice, compressing the options collection. Note that removal of option objects can also be achieved by setting their
value property to "" (i.e. null).
© 1995-1998, Stephen Le Hunte
|file: /Techref/language/html/ib/Scripting_Reference/optcol.htm, 5KB, , updated: 2004/3/1 16:47, local time: 2018/8/20 13:19,
|©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/language/html/ib/Scripting_Reference/optcol.htm"> The Options collection</A>
|Did you find what you needed?|
PICList 2018 contributors:
o List host: MIT, Site host massmind.org, Top posters @20180820 RussellMc, Van Horn, David, Sean Breheny, David C Brown, Isaac M. Bavaresco, Bob Blick, Neil, John Gardner, Denny Esterline, Brent Brown,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!