User Guide

390 Chapter 2: ColdFusion Tags
Note: Attributes that are marked as Flash only are not handled by the skins provided with ColdFusion
MX. They are, however, included in the generated XML.
Usage
This tag requires an end tag and can include HTML option and optgroup child tags.
To ensure that a selected list box item persists across postbacks, use the
cfform preserveData
attribute with a list generated from a query.
(This strategy works only with data that is populated
from a query.)
If the
cfform preserveData attribute is true and the form posts back to the same page, and if
the control is populated by a query, the posted selection(s) for the
cfselect control are used
instead of the
Selected attribute. For controls that are populated with regular HTML option
tags, the developer must dynamically add the
Selected attribute to the appropriate option tag(s).
The
group option generates a query using SQL GROUP BY syntax and places the value column
entries from each group in an indented list under the
group columns field value. This option
generates an HTML
optgroup tag for each entry in the group column.
Close each HTML
option tag in the cfselect tag body with a </option> end tag. If you do
not do so, and you specify
queryPosition="below", the first item from the query might not
appear in the list.
For this tag to work properly. the browser must be JavaScript-enabled.
For more information, see the
cfform tag entry.
Example
The following example lets you select one or more employee names from a list of all employees,
grouped by departments, and displays the selected names and the employees email addresses. It
includes an option to get data for all employees.
<!--- Get the employee names from the database. --->
<!--- Use SQL to create a Name field with first and last names. --->
<cfquery name = "GetAllEmployees" dataSource = "cfdocexamples"
cachedwithin="#createTimeSpan(0,1,0,0)#">
SELECT Emp_ID, EMail, Phone, Department, FirstName, LastName, FirstName +' '
+lastName as Name
FROM Employees
GROUP BY Department, Emp_ID, EMail, Phone, FirstName, LastName, FirstName
</cfquery>
<h2>cfselect Example</h2>
<!-- The cfif statement is true if the form was submitted.
height Optional;
Flash
The height of the control, in pixels.
width Optional;
Flash
The width of the control, in pixels.
Attribute Req/Opt;
Format
Default Description