<CFSELECT NAME="name
" REQUIRED="Yes/No" MESSAGE="text" ONERROR="text" SIZE="integer" MULTIPLE="Yes/No
" QUERY="queryname" SELECTED="column_value" VALUE="text" DISPLAY="text"> </CFSELECT>
Used inside CFFORM, CFSELECT allows you to construct a drop-down list box form control. You can populate the drop-down list box from a query, or using the OPTION tag. Use OPTION elements to populate lists. Syntax for
the OPTION tag is the same as for its HTML counterpart.
You can add standard FORM tag attributes and their values to the CFSELECT tag. These attributes and values are passed directly through Cold Fusion to the browser in creating a form. For example, FORM tag attributes,
like TARGET can be used to enhance your CFFORM features.
CFSELECT supports the JavaScript onClick event in the same manner as the HTML INPUT tag:
<CFSELECT NAME="dept" MESSAGE="You must select a department name" QUERY="get_dept_list" VALUE="dept_name"
onClick="JavaScript_function
">
Attributes
NAME |
Required. A name for the form you are creating. |
REQUIRED |
Optional. Yes or No. If Yes, a list element must be selected when the form is submitted. Default is No. |
MESSAGE |
Optional. Message that appears if REQUIRED="Yes" and no selection is made. |
ONERROR |
Optional. The name of a valid JavaScript function you want to execute in the event of a failed validation. |
SIZE |
Optional. Size of the drop-down list box in number of entries. |
MULTIPLE |
Optional. Yes or No. Yes permits selection of multiple elements in the drop-down list box. The default is No. |
QUERY |
Optional. Name of the query to be used to populate the drop-down list box. |
SELECTED |
Optional. Enter a value matching at least one entry in VALUE to preselect the entry in the drop-down list box. |
VALUE |
Optional. The query column value for the list element. Used with the QUERY attribute. |
DISPLAY |
Optional. The query column displayed. Defaults to the value of VALUE. Used with the QUERY attribute. |
Example
This example populates the CFSELECT from a query called "get_dept_list" and preselects the value for "dept_name".
<CFSET selected="form.dept"> <CFFORM NAME="update" ACTION="update.cfm"> <CFSELECT NAME="dept" REQUIRED="Yes" MESSAGE="You must select a department name" SIZE="20" MULTIPLE="no" QUERY="get_dept_list" SELECTED="#selected#" VALUE="dept_name">
This example populates the CFSELECT using OPTION tags and preselects the third list item:
<CFSELECT NAME="homes" SIZE="3" REQUIRED="no"> <OPTION VALUE="one">list item one <OPTION VALUE="two">list item two <OPTION VALUE="three" SELECTED>list item three <OPTION VALUE="four">list item four <OPTION VALUE="five">list item five </CFSELECT>
|