25.30. The Select Object

A Select object corresponds to an HTML element created through <SELECT ...>. It is normally accessed through the elements array of the enclosing Form. If the Form and Select objects both have names, you can also use document.formName.selectName.

Listing 25.4 shows a page that presents a pull-down menu of color choices. Choosing an entry changes the page's background color.

Listing 25.4. SelectColor.html
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Changing the Background Color</TITLE> <SCRIPT TYPE="text/javascript"> <!-- function setBackgroundColor() { var selection = document.colorForm.colorSelection; document.bgColor = selection.options[selection.selectedIndex].value; } // --> ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.