OBJECT:  Option


new Option([text[, value[, defaultSelected[, selected]]]])
 
An Option object is created for every option in a selection list, and is put in the options property of the Select object. It can be created in one of two ways: you can either use the HTML <OPTION> tag, or use the Option constructor. Using HTML you could create a 'Dachshund' option for a selection list of dog breeds as follows:
 
Code:
<option> Dachshund
 
You could also create the same option using the Option constructor and assigning it to an index of the options property of the relevent Select object:
 
Code:
document.myForm.dogBreed[4] = new Option("Dachshund")
 
After creating an Option object in this way you must refresh the document by using history.go(0) at the end of the code. Using the Option constructor, you can optionally specify a value to be returned to the server when an option is selected and the form submitted (in this case "dachs"):
 
Code:
new Option("Dachshund", "dachs")
 
It is also possible to designate the option to be the pre-selected default selection in the option box display (i.e., this option has the HTML "selected" attribute included inside the "option" tag). This is done by setting the defaultSelected argument to be true.
 
Code:
new Option("Dachshund", "dachs", true)
 
The selected argument is used for multiple selections.
 
PROPERTIES
 
defaultSelected Property
This property, by default tainted, is a Boolean value which initially reflects whether an option was declared with the HTML SELECTED attribute, reading true if it was and false if not
 
Syntax: object.defaultSelected
 
selected Property
This property, which is tainted by default, is a Boolean value reflecting whether a particular option is selected, returning true if it is and false if not. The selected property can be set at any time, immediately updating the display of the Select object.
 
Syntax: object.selected
 
text Property
This property, by default tainted, reflects the text value following any particular HTML OPTION tag for a Select object. It can be reset at any time, immediately updating the display of the selection.
 
Syntax: object.text
 
value Property
This property, tainted by default, is a string value that is returned to the server when an option is selected and the form submitted. It reflects the VALUE attribute in the HTML. If there is no VALUE attribute, then the value property is an empty string.
 
Syntax: object.value
 
METHODS
 
The Select object inherits the watch and unwatch methods from the Object object.


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information