HTML and CSS Reference
In-Depth Information
Figure 11.38
After the user selected the third option in the menu, the textbox is
updated dynamically.
Figure 11.39
The user selects another menu item.
Multiple Selects.
If you use the
multiple
attribute of a select list, more than one
option can be selected. To select more than one item, hold down the Control key while
clicking on an item. If more than one item is chosen, the
selectedIndex
value will indicate
only the first one that was selected. To test whether more than one option has been
selected, you can use the
selected
property of the
options
object. This property will result
in
true
if an option has been selected;
false
otherwise. See Example 11.23.
EXAMPLE
11.23
<html>
<head><title>Drop Down Menus</title>
<script type="text/javascript">
1
function showme(form)
{
2
var choices="";
3
for (i=0;i<
form.vacation.options.length
;i++){
4
if(
form.vacation.options[i].selected
== true){
5
choices += form.vacation.options[i].text
+"\n";
}
}
6
alert(choices);
}
</script>
</head>