
Selection lists in HTML FORMS appear as drop-down menus
or scrollable lists of selectable items. Lists are built using two: <SELECT>
and <OPTION>. for instance, the
following code:
creates a three-item, drop-down menu with the choices 1, 2, and 3. Using the SIZE attribute you can create a scrollable list with the number of elements visible at one time indicated by the value of SIZE attribute. To turn your drop-down menu into a scrollable menu with two visible items you could use the following:
In both of these examples, the user can make only one choice. Using the MULTIPLE attribute, you can enable the user to select more than one choice in a scrollable selection list:
The <OPTION> tag consists of two "value" parts: 1) "value" & 2) "text"
Selection lists are accessible in JavaScript through the <SELECT> Object. This object bears some similarity to both the buttons as well the radio buttons. Properties
As with radio buttons, the list of options is maintained as an Array with indexes starting at zero. In this case, the array is a property of the <SELECT> Object is called options. Both selection option and the individual option elements have properties. In addition to the options array, the select object has the selectedIndex property, which contains the index number of the currently selected option. Each option in a s selection list also has several properties. defaultSelected indicates whether the option is selected by default in the <OPTION> tag. The index property contains the index value of the current option in the options[] array. Again, as you might expect, selected indicates the current status of the option, text contains the value of the text displayed in the menu for the specific option, and value contains any value indicated in the <OPTION> tag. The <SELECT> Object has no available methods. However, the <SELECT> Object has an Event Handler - onChange. For example, if you have the following selection list:
then when the list is first displayed, you have would have access to the following information:
|