Select Object
For each instance of an HTML <select> tag on a form, a Select object is created.
All Select objects are stored in the elements array of the corresponding
form. You can access a Select object by indexing this array - either by number
(0 represents the first element in a form) or by using the value of the name
attribute.
The Select object's collections, properties, methods, and events are
described below:
N: Netscape (including Mozilla when N6 or higher), IE: Internet Explorer, W3C: World Wide Web Consortium (Internet Standard)
Collections
Collection |
Description |
N |
IE |
W3C |
options |
Returns an array of all the options in a dropdown list (one element for each <option> tag
- starting at 0) |
2 |
3.02 |
Yes |
Properties
Syntax: object.property_name
Property |
Description |
N |
IE |
W3C |
accessKey |
Sets or returns the keyboard key to access the dropdown
list |
|
4 |
No |
align |
Sets or returns the alignment of the dropdown list
according to the surrounding text |
|
4 |
No |
disabled |
Sets or returns whether or not the dropdown list should be
disabled |
6 |
5.5 |
Yes |
form |
Returns a reference to the dropdown list's parent form |
2 |
3.02 |
Yes |
id |
Sets or returns the id of the dropdown list (In IE 4 this
property is read-only) |
|
4 |
No |
length |
Sets or returns the number of options in the dropdown list |
2 |
3.02 |
Yes |
multiple |
Sets or returns the Boolean value indicating whether
multiple items can be selected |
6 |
3.02 |
Yes |
name |
Sets or returns the name of the dropdown list |
2 |
3.02 |
Yes |
selectedIndex |
Sets or returns the index of the selected option in the
dropdown list. Note: If the dropdown list allows for multiple selections
it will only return the index of the first option selected |
2 |
3.02 |
Yes |
size |
Sets or returns the number of rows in the dropdown list |
6 |
3.02 |
Yes |
tabIndex |
Sets or returns the tab order for the dropdown list |
|
5 |
Yes |
type |
Returns the type of the form element. For a dropdown list it will
be "select-one" or "select-multiple" |
3 |
4 |
Yes |
value |
Sets or returns the value to be returned to the server when
the form is submitted |
6 |
3.02 |
Yes |
Methods
Syntax: object.method_name()
Method |
Description |
N |
IE |
W3C |
add() |
Adds an option to the dropdown list |
|
4 |
Yes |
blur() |
Removes focus from the dropdown list |
3 |
4 |
Yes |
focus() |
Sets focus on the dropdown list |
3 |
4 |
Yes |
remove() |
Removes an option from the dropdown list |
6 |
4 |
Yes |
Events
Syntax: object.event_name="someJavaScriptCode"
Event |
Description |
N |
IE |
W3C |
onBlur |
Executes some code when the dropdown list loses focus |
2 |
3.02 |
|
onChange |
Executes some code when the dropdown list loses focus and its
value has altered |
2 |
3.02 |
|
onClick |
Executes some code when the user clicks the left mouse
button in the dropdown list |
|
4 |
|
onFocus |
Executes some code when the dropdown list gets focus |
2 |
4 |
|
|