• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 13. Working with Text and Select... > Creating New Options in a <SELECT> C...

Creating New Options in a <SELECT> Control

You can change the items in a <SELECT> control on-the-fly. Not only can you change the text property (and therefore the caption) of each item in a <SELECT> control, you also can add or remove items using the add and remove methods. The catch here is that the add and remove methods are methods of the <SELECT> control itself in the Netscape Navigator (see Table 13.11), and of the options collection in the Internet Explorer (see Table 13.15).

Here’s an example that shows how to change the items in a <SELECT> control when the user clicks buttons. The <SELECT> control here will display a list of three colors (red, white, and blue) when it first appears, and when you click the Colors button, or four numbers (1, 2, 3, and 4) when you click the Numbers button. To do this, it has to add and remove items as needed, using both the Netscape Navigator 6+ (earlier versions do not support functions like remove and createElement) and Internet Explorer syntax. Here’s what the code looks like:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint