OBJECT: Select
The Select object represents a selection list in a Form object. As such, it must be declared
inside <FORM> tags. The JavaScript runtime engine creates such an object
for every selection list in a particular form, and assigns it to the Form's elements array.
It is through this array that a particular Select object can be accessed,
either by index-number or by its NAME attribute.
PROPERTIES
form Property
This property is a reference to the parent form to which a particular Select
object belongs.
Syntax: object.form
length Property
This property contains the number of options in the selection list. For example, to refer
to the length of the first Select object in the first form of the current document,
you could use the following code:
Code:
document.forms[0].elements[0].length
Syntax: object.length
name Property
This property consists of a string which gives the name of the selection. For example, to refer
to the name of the first Select object in the first form of the current document,
you could use the following code:
Code:
document.forms[0].elements[0].name
Syntax: object.name
options Property
This property is an array of all the options in a particular Select object. There is one
element (numbered in ascending order from zero) for each <OPTION> tag.
Syntax: object.options
selectedIndex Property
This property, which is tainted by default, is an integer relating to the currently-selected option
of a Select object. If, however, the Select object allows for multiple selections
(i.e. when the <SELECT> tag includes the MULTIPLE attribute),
the selectedIndex property will only return the index of the first option selected.
For example, the following code would return the index of the selected option of a Select
object called MySelect in MyForm:
Code:
document.myForm.mySelect.selectedIndex
Syntax: object.selectedIndex
type Property
This property holds the type of the Select object, having the value "select-one"
where only one option can be selected and "select-multiple" where multiple selections are possible.
The following code could be used to determine the type of the first Select object
of the first form of the current document:
Code:
document.forms[0].elements[0].type
Syntax: object.type
METHODS
blur Method
This method removes focus from a selection list.
Syntax: object.blur()
focus Method
This method moves the focus to the specified selection list allowing the user to then
select from it.
Syntax: object.focus()
handleEvent Method
This method calls the handler for a specified event.
Syntax: object.handleEvent(event)
NOTE:
The Select object also inherits the watch and
unwatch methods from the Object
object.
EVENT HANDLERS
onBlur EventHandler
This event handler causes JavaScript code to be executed whenever a blur event occurs;
i.e. whenever a window, frame or form element loses focus.
Syntax: onBlur = "myJavaScriptCode"
onChange EventHandler
This event handler executes JavaScript code whenever a Select, Text
or Textarea field loses focus after having been altered.
Syntax: onChange = "myJavaScriptCode"
onFocus EventHandler
This event handler executes JavaScript whenever a focus event occurs; i.e.
whenever the user focuse on a window, frame or frameset, or inputs to a form element.
Syntax: onFocus = "myJavaScriptCode"
|