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.
<CFSELECT NAME="name" REQUIRED="Yes/No" MESSAGE="text" ONERROR="text" SIZE="integer" MULTIPLE="Yes/No" QUERY="queryname" SELECTED="column_value" VALUE="text" DISPLAY="text" PASSTHROUGH="HTML_attributes"> </CFSELECT>
Required. A name for the form you are creating.
Optional. Size of the drop-down list box in number of entries.
Optional. Yes or No. If Yes, a list element must be selected when the form is submitted. Default is No.
Optional. Message that appears if REQUIRED="Yes" and no selection is made.
Optional. The name of a valid JavaScript function you want to execute in the event of a failed validation.
Optional. Yes or No. Yes permits selection of multiple elements in the drop-down list box. The default is No.
Optional. Name of the query to be used to populate the drop-down list box.
Optional. Enter a value matching at least one entry in VALUE to preselect the entry in the drop-down list box.
Optional. The query column value for the list element. Used with the QUERY attribute.
Optional. The query column displayed. Defaults to the value of VALUE. Used with the QUERY attribute.
Optional. HTML attributes that are not explicitly supported by CFSELECT. If you specify an attribute and its value, the attribute and its value are passed to the HTML code that is generated for the CFSELECT tag. See the Usage section for more information about specifying values.
You can add standard and dynamic HTML FORM tag attributes and their values to the CFSELECT tag by using the PASSTHROUGH attribute. These attributes and values are passed directly through ColdFusion to the browser in creating a form.
If you specify a value in quotation marks, you must escape the quotation marks by doubling them, for example,
PASSTHROUGH= "readonly= " "YES " " "
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">
<!--- This example shows the use of CFTREE, CFSELECT and CFGRID in a CFFORM. The query takes a list of employees, and uses CFTREE and CFSELECT to display the results of the query. In addition, CFGRID is used to show an alternate means of displaying the same data ---> <!--- set a default for the employeeNames variable ---> <CFPARAM NAME="employeeNames" DEFAULT=""> <!--- if an employee name has been passed from the form, set employeeNames variable to this value ---> <CFIF IsDefined("form.employeeNames") is not "False"> <CFSET employeeNames = form.employeeNames> </CFIF> <!--- query the datasource to find the employee information---> <CFQUERY NAME="GetEmployees" DATASOURCE="cfsnippets"> SELECT Emp_ID, FirstName, LastName, EMail, Phone, Department FROM Employees where lastname <CFIF #employeeNames# is not "">= '#employeeNames#'</CFIF> </CFQUERY> <HTML> <HEAD> <TITLE> CFSELECT Example </TITLE> </HEAD> <BODY> <H3>CFSELECT Example</H3> <!--- Use CFFORM when using other CFINPUT tools ---> <CFFORM ACTION="cfselect.cfm" METHOD="POST" ENABLECAB="Yes"> <!--- Use CFSELECT to present the contents of the query by column ---> <H3>CFSELECT Presentation of Data</H3> <H4>Click on an employee's last name and hit "see information for this employee" to see expanded information.</H4> <CFSELECT NAME="EmployeeNames" MESSAGE="Select an Employee Name" SIZE="#getEmployees.recordcount#" QUERY="GetEmployees" VALUE="LastName" REQUIRED="No"> <OPTION value="">Select All </CFSELECT> ...