A Selection Control
The
CFSELECT
tag extends the functionality provided by
the HTML SELECT
tag by including data validation
as well as a mechanism for quickly and easily building dynamic
drop-down boxes from query results. Example 10-5
shows a simple use of CFSELECT
with static option
values.
Example 10-5. Using CFSELECT with Static Option Values
<CFIF IsDefined('Form.Selectbox')> <CFOUTPUT>You submitted <B>#Form.Selectbox#</B>.</CFOUTPUT> <HR NOSHADE> </CFIF> <CFFORM ACTION="Example10-5.cfm" ENABLECAB="Yes" NAME="MyForm" ENCTYPE="application/x-www-form-urlencoded"> <CFSELECT NAME="Selectbox" SIZE="5" MESSAGE="You must select at least one item from the selection box." REQUIRED="Yes" MULTIPLE="Yes"> <OPTION VALUE="January">January <OPTION VALUE="February">February <OPTION VALUE="March">March <OPTION VALUE="April">April <OPTION VALUE="May">May <OPTION VALUE="June">June <OPTION VALUE="July">July <OPTION VALUE="August">August <OPTION VALUE="September">September <OPTION VALUE="October">October <OPTION VALUE="November">November <OPTION VALUE="December">December </CFSELECT> <P> <INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form"> </CFFORM>
In Example 10-5, a drop-down box is created within a
CFFORM
using the CFSELECT
tag.
We specify the name of the select-box field using the
NAME
attribute. Setting the
SIZE
to 5
creates a select box
five rows high. Note that SIZE
must be set to at
least two (2) for the REQUIRED
validation to work.
The MULTIPLE
attribute allows the user to select ...
Get Programming ColdFusion now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.