OPTION
in a SELECT
form element.
Server-side function | |
Implemented in | LiveWire 1.0 |
Syntax
getOptionValue(name, index)
Parameters
name |
A name specified by the NAME attribute of the SELECT tag
|
index | Zero-based ordinal index of the selected option. |
Returns
A string containing the text for the selected option, as specified by the associated OPTION
tag.
Description
The getOptionValue
function is a top-level server-side JavaScript function not associated with any object. It corresponds to the Option.text
property available to client-side JavaScript.
The SELECT
tag allows multiple values to be associated with a single form element, with the MULTIPLE
attribute. If your application requires select lists that allow multiple selected options, you use the getOptionValue
function to get the values of selected options in server-side JavaScript.
Examples
Suppose you have the following form element:
<SELECT NAME="what-to-wear" MULTIPLE SIZE=8>
You could process the input from this select list in server-side JavaScript as follows:
<OPTION SELECTED>Jeans
<OPTION>Wool Sweater
<OPTION SELECTED>Sweatshirt
<OPTION SELECTED>Socks
<OPTION>Leather Jacket
<OPTION>Boots
<OPTION>Running Shoes
<OPTION>Cape
</SELECT><SERVER>
If the user kept the default selections, this script would return
Item #1: Jeans
var loopIndex = 0
var loopCount = getOptionValueCount("what-to-wear") // 3 by default
while ( loopIndex < loopCount ) {
var optionValue = getOptionValue("what-to-wear",loopIndex)
write("<br>Item #" + loopIndex + ": " + optionValue + "\n")
loopIndex++
}
</SERVER>
Item #3: Sweatshirt
Item #4: Socks
See also
getOptionValueCount
Last Updated: 10/31/97 16:38:00