HTML and CSS Reference
In-Depth Information
EXAMPLE
11.23 (
CONTINUED
)
<body bgcolor="lightgreen">
<font face="arial">
<b>
7
<form name="form1" onSubmit="showme(this);"
/>
Where do you want to go? <br />
8
<select name="vacation" size=4 multiple>
<option>Maui</option>
<option>Jamaica</option>
<option>Bali</option>
<option>Virgin Islands</option>
</select>
<p></p>
</b>
<input type="submit" />
<input type="reset" />
</form>
</font>
</body>
</html>
EXPLANATION
1
The function called
showme()
is defined. It is passed one parameter, a reference to
a
form
object.
2
The variable called
choices
is declared and assigned an empty string.
3
The
for
loop is entered. The initial value,
i
, is set to 0. As long as the value of
i
is
less than the length of the options array, the body of the loop will be entered; thus,
as long as we haven't looped through all the options in the menu, the loop will be
entered.
4
If the option from the menu was selected, the
selected
property will evaluate to
true
.
5
If an option was selected, the variable, called
choices
, will be assigned the text val-
ue of the option; perhaps
Maui
or
Bali
will be assigned to
choices
. Each time
through the
for
loop, if an option is selected, it will be appended to the variable,
resulting in a string that contains all of the selected options.
6
The alert dialog box will display the string value containing all the options that
were selected.
7
The HTML form called
form1
starts here.
8
The HTML select menu called
vacation
starts here. It will contain four menu op-
tions, and allow multiple selections. See Figure 11.40.