Main Page

List Boxes and Combo Boxes

if (iMin == null || iValue > parseInt(iMin)) {
oTextbox.value = (iValue - 1);
}
}
};
The few lines added to the method do some very specific things. First, the minimum and maximum val-
ues are retrieved from the custom attributes. Then, when each key is tested, a test checks whether the min-
imum and maximum values have been specified. If the attributes haven’t been specified,
iMax
and
iMin
are equal to
null
. If they aren’t
null
,
parseInt()
is called to get the integer value of the attributes. This
value is then compared with the value in the text box to determine it is should be changed (incremented
or decremented) or not.
To use this functionality, just add either the
min
attribute or the
max
attribute (or both) to the
<input/>
tag:
<input type=”text” onkeypress=”return TextUtil.allowChars(this, event)”
validchars=”0123456789” onblur=”TextUtil.blurAllow(this)”
onkeydown=”TextUtil.numericScroll(this, event)”
max=”100” min=”0” />
Using this code, the values will stop incrementing and decrementing when either of these limits is hit.
List Boxes and Combo Boxes
List boxes and combo boxes are created using the HTML
<select/>
element. By default, the browser
renders the
<select/>
element as a combo box:
<select name=”selAge” id=”selAge”>
<option value=”1”>18-21</option>
<option value=”2”>22-25</option>
<option value=”3”>26-29</option>
<option value=”4”>30-35</option>
<option value=”5”>Over 35</option>
</select>
The
value
attribute of each
<option/>
is used to determine the value for the control as a whole; the
selected option gives its
value
to the control (so it can be sent to the server).
To render this same code as a list box, you need only add the
size
attribute and indicate how many
items you want visible at the same time. For example, the following displays a list box with three items
visible at once.
<select name=”selAge” id=”selAge” size=”3”>
<option value=”1”>18-21</option>
<option value=”2”>22-25</option>
<option value=”3”>26-29</option>
<option value=”4”>30-35</option>
<option value=”5”>Over 35</option>
</select>
356
Chapter 11
14_579088 ch11.qxd 3/28/05 11:40 AM Page 356


JavaScript EditorFree JavaScript Editor     Ajax Editor


©