For standard HTML attribute information about the <SELECT>
element, see the <SELECT>
topic.
Currently, the <SELECT>
element accepts four scripting attributes (at least as far as browser documentation is concerned). The three that are mentioned in the Cougar W3C draft specification work in both browsers, but the OnClick
event (mentioned in Netscape documentation) appears not to be properly supported and is not mentioned in the Cougar draft specification.
OnBlur
The OnBlur
event can be used to execute script functions when the user moves the focus away from the <SELECT>
element (i.e. they move to another form element). For example, consider the <SELECT>
section of the example form provided on the Forms Introduction topic :
<SELECT NAME="Choice">
<OPTION>Outstanding
<OPTION>Very good
<OPTION>Good
<OPTION>Average
<OPTION>Below Average
<OPTION>Awful
<OPTION SELECTED>My response would be "indecent" under the CDA Act.
</SELECT>
If we add the OnBlur
event handler (see below) to call the script function (see below), then some simple interactivity to the users choices can be included
<SELECT NAME="Choice" OnBlur="reply(document.egForm.Choice.selectedIndex)">
. . .
</SELECT>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub reply (choice_made)
if choice_made="0" then alert "Thanks very much, I'm glad you like it"
if choice_made="2" then alert "You really are too kind"
if choice_made="4" then alert "You certainly are hard to please"
if choice_made="6" then alert "Go on, swear at me, I dare you"
End Sub
-->
</SCRIPT>
The event handler passes the selectedIndex
of the various <OPTION>
choices and reacts accordingly. Give it a try (Select a choice in the drop down box, then click the radio button to fire the OnBlur
event :
OnChange
The OnChange
event can be used to execute scripting functions when the user changes the selection made in the <SELECT>
drop-down choice box. The above example can be re-used and work just as well, if the event handler is changed to OnChange
instead of OnBlur
.
OnClick
In official Netscape documentation, they detail support for the OnClick
event, but on testing, it did not appear to work. Also, the OnClick
event is not detailed in the W3C Cougar specification.
OnFocus
This event handler can be used to execute script functions when the <SELECT>
element receives the users focus. Again, the first example given in this topic can be re-used, changing the OnBlur
event to the OnFocus
event handler.