592 Part III . (Web hosting faq) Document Objects Reference other

592 Part III . Document Objects Reference other than the wording displayed in the list. In essence, your script can act on that hidden value rather than on the displayed text, such as letting a plain-language select listing actually refer to a complex URL. This string value is also the value sent to a CGI program (as part of the name/value pair) when the user submits the SELECT object s form. One behavioral aspect of the SELECT object may influence your page design. The onChange event handler triggers immediately when a user makes a new selection in a pop-up list (except in cases affected by a Navigator 2 bug on Windows versions). If you prefer to delay any action until the user makes other settings in the form, omit an onChange event handler in the SELECT object but be sure to create a but ton that enables users to initiate an action governed by those user settings. Modifying SELECT options (NN3+, IE4+) Script control gives you considerable flexibility in modifying the contents and selection of a SELECT object. These powers are available only in NN3+ or IE4+. Some of this flexibility is rather straightforward, such as changing the selectObj.options[i].text property to alter the display of a single-option entry. The situation gets tricky, though, when the number of options in the SELECT object changes. Your choices include . Removing an individual option (and thus collapsing the list) . Reducing an existing list to a fewer number of options . Removing all options . Adding new options to a SELECT object To remove an option from the list, set the specific option to null. For example, if a list contains five items and you want to eliminate the third item altogether (reduc ing the list to four items), the syntax (from the SELECT object reference) for doing that task is this: selectObj.options[2] = null After this statement, selectObj.options.length equals 4. In another scenario, suppose that a SELECT object has five options in it and you want to replace it with one having only three options. You first must hard-code the length property to 3: selectObj.options.length = 3 Then, set individual textand value properties for index values 0through 2. Perhaps you want to start building a new list of contents by completely deleting the original list (without harming the SELECT object). To accomplish this, set the length to 0: selectObj.options.length = 0 From here, you have to create new options (as you do when you want to expand a list from, say, three to seven options). The mechanism for creating a new option involves an object constructor: new Option(). This constructor accepts up to four parameters, which enable you to specify the equivalent of an

Leave a Reply