HTML and CSS Reference
EXAMPLE 14.28 ( CONTINUED )
This is a test.
The number, selectedIndex , of the option chosen from a select list is assigned to
variable i .
The value of the selected option is one of the colors listed in the select list on line 8.
The getElementById() method returns a reference to the body tag, whose id is bdy .
By using the style property with the reference to the body, the background color
of the document is changed with this statement.
The body tag is given an id attribute by which to identify it.
An HTML form called form1 starts here.
A select menu is defined to give the user options to change the background color
of the document on the fly. The onChange event is triggered when one of the op-
tions is selected, and is handled by invoking the function bodyColor() . The output
is shown in Figure 14.33.
Figure 14.33 Changing the background color dynamically (left); now the color is green