please dont rip this site
The Options Collection

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.:

document.<SELECT>reference.options(1).value

returns the VALUE attribute of the second <OPTION> element in the <SELECT> element referenced by <SELECT>reference. For example, consider the following:

<SELECT NAME="Songs">
<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
<SELECT>

Calling the following in a script function:

document.Songs.options(1).value

would return JacketHangs.

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.

E.g.

document.Songs.options('Lover').text

would return the Lover And Confidante - the displayed text for the <OPTION> element whose ID attribute is 'Lover'.

Properties

length
The 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 document.<SELECT>reference.options(2).property

Methods

add
The 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.

The 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
The item method retrieves single items, or sub-collections from an areas collection. It accepts the following arguments:

options.item(index, sub-index)

If index is a number, then the method returns a reference to the <OPTION> at that position in the options collections index. I.e.

strTag=document.<SELECT>reference.options.item(2).value

would make strTag be the value of the VALUE attribute of the <SELECT>'s third <OPTION>. As you can see, this is effectively the long-hand version of using document.<SELECT>reference.options(2).property.

If the 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 NAME or 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
The remove method can be used to remove an option object from a select object. For example, using the <SELECT>/<OPTION> set from above, using:

document.Songs.options.remove(1)

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).


file: /Techref/language/html/ib/Scripting_Reference/optcol.htm, 5KB, , updated: 2004/3/1 16:47, local time: 2024/3/29 07:31,
TOP NEW HELP FIND: 
54.210.143.119:LOG IN

 ©2024 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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.sxlist.com/techref/language/html/ib/Scripting_Reference/optcol.htm"> The Options collection</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to www.sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .