getOptionValue()

Nes2+Syntax

getOptionValue(key, num)

Description

The getOptionValue function is a top-level function that is not associated with any object. This function returns the same value as the client-side Option.text property. The key passed in as an argument represents the NAME attribute of the <SELECT> tag, while the num parameter is the indexed position of the selected option. Specifying num to 0 can reference the first selected option, which may not be the first option.

Example

Listing 8.91 displays a multi-select option box that allows a user to select different sports. When the Submit button is clicked, the form is sent back to itself and the script then uses a for loop and the getOptionValue function to write the submitted ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.