HTML and CSS Reference
EXAMPLE 11.21 ( CONTINUED )
<option name="choice3" value="Unix1">Intro to
<option name="choice4" value="Shell1">Shell
<br /><br />
document.write("The name of the selection list is ",
document.write("<br />The number of items in the selection"+
"list is ", document.form1.menu1.length );
document.write("<br />The item currently selected is option["+
document.form1.menu1.selectedIndex + "]");
document.write("<br />The text in the first selection is "+
document.write("<br />The text in the second selection is "+
The HTML form named form1 starts here. The action and method attributes are not
included here because this form is not being sent to a server.
The select tag starts a drop-down list named menu1 ; it has four options.
The options that will appear in the menu are listed.
This ends the select list.
The name of the select object is displayed.
The number of options in the select list is displayed.
The index value of the option selected by the user is displayed. If no option has
been selected, the value of selectedIndex is - 1 . If one has been selected, the index
value of the option is displayed. The options are in an array where the index starts
at 0. The first option is at index 0, the second option is index 1, and so on.
The actual text shown in the list for the first option is displayed, followed by the
text in the second selection. The output is shown in Figures 11.36 and 11.37.