Changing Menus Dynamically

It’s often useful to offer the user a choice of inputs via pop-up menus, and to be able to change the contents of one or more pop-up menus depending on the choice the user makes in another pop-up menu. You’ve probably seen this on Web sites that ask you to choose the country you live in from a pop-up menu and then fill a second menu with state or province names, based on the choice you made. In Scripts 7.3 (HTML) and 7.4 (JavaScript), we’re using two pop-up menus (Figure 7.3). The first menu is for months. When the user picks a month, the script populates the second pop-up menu with the correct number of days for the selected month (Figure 7.4).

Figure 7.3. The contents of the second menu are filled in automatically ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.