How list box values can be accessed in the form processing
There are times when a text box just wont cut it. Perhaps you want to restrict
the user to a specific set to choice. For example, if you want users to specify
their states of residency, you dont want to use a text box because some
one might misspell a states name or enter 41 as his state of residency.
When you need users to choose a response to a particular set of valid options,
it is best to use a list box.
Of all the
form field type, the list box is the oddball, being the only one than isnt
created via the<INPUT> tag. Rather, the list box uses two tags, the <SELECT>
and the <OPTION> tags. The <SELECT> tag indicates that a list box
will be created, where as each <OPTION> tag represents a unique choice for
the list box.
<SELECT> tag has two properties that we will discuss: the NAME property
and the SIZE PROPERTY. The name property serves the same purpose as with the text
box form field type it uniquely identifies the particular list box. The SIZE property
determines how many list options are shown at one time. The default value for
the SIZE PROPERTY is 1, which means that a list box, by default, will show only
one option at a time. Display a list box with the default SIZE PROPERTY AND A
LIST BOX WITH A SIZE property.
<OPTION> tag has two important properties. The first is the value property,
which uniquely identifies each separate list box option. When the user selects
a list box option and submits the form, the form processing script is passed the
string in the value property of the selected list box item. The value property
does not determine what is displayed in the list box. Examine the code in listing.
This is the code that, when viewed through a browser.
the <OPTION> Tag
<HTML> 2: <BODY> 3: <FORM METHOD=GET ACTION = /Scripts/Somefile.asp> 4:
This list box has its SIZE Property set to the default 5: <BR> 6:
<SELECT NAME = ASPOption> 7: <OPTION VALUE=5> i like
ASP a lot! </OPTION> 8: <OPTION VALUE = 4>asp SURE
IS NEAT. </OPTION> 9: <OPTION VALUE= 3 > its
Interesting </OPTION> 10: <OPTION VALUE = 2 >ASP is
difficult! </OPTION> 11: <OPTION VALUE= 1>Ah! </OPTION> 12:
</select> 13: <P> 14: This list box has its SIZE property set
to 5: 15: <BR> 16: <SELECT NAME = Experiences SIZE = 5> 17:
<OPTION VALUE = 10 > 10 YEARS OF asp Experience </OPTION> 18:
<OPTION VALUE = 9 > 9 YEARS OF asp Experience </OPTION> 19:
<OPTION VALUE = 8 > 8 YEARS OF asp Experience </OPTION> 20:
<OPTION VALUE = 7 > 7 YEARS OF asp Experience </OPTION> 21:
<OPTION VALUE = 6 > 6 YEARS OF asp Experience </OPTION> 22:
<OPTION VALUE = 5 > 5 YEARS OF asp Experience </OPTION> 23:
<OPTION VALUE = 4 > 4 YEARS OF asp Experience </OPTION> 24:
<OPTION VALUE = 3 > 3 YEARS OF asp Experience </OPTION> 25:
<OPTION VALUE = 2 > 2 YEARS OF asp Experience </OPTION> 26:
<OPTION VALUE = 1 > 1 YEARS OF asp Experience </OPTION> 27:
<OPTION VALUE = 0 > Less than a year of asp Experience </OPTION> 28:
</SELECT> 29: </BODY > 30: </HTML>