Constructs a drop-down list box form control. Used in a cfform tag. You can populate the list from a query, or by using the HTML option tag.



name="name" bind="bind expression" 
bindAttribute="attribute name" 
display="text" editable="yes|no" 
group="query column name" height="number of pixels" 
id="HTML id" 
label="label" message="text" multiple="yes|no" 
onBindError="JavaScript function name" 
onChange="JavaScript or ActionScript" 
onClick="JavaScript function name" 
onKeyDown="JavaScript or ActionScript" 
onKeyUp="JavaScript or ActionScript" 
onMouseDown="JavaScript or ActionScript" 
onMouseUp="JavaScript or ActionScript" 
query="query name" queryPosition="above|below" 
selected="value or list" size="integer" sourceForTooltip="URL" 
style="style specification" tooltip="text" 
value="text" visible="yes|no" 
width="number of pixels"> 
zero or more HTML option tags 

Some attributes apply to only specific display formats. For details see the Attributes table.


You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.

See also


ColdFusion 11:

  • Removed the attribute passthrough.

ColdFusion 8:

  • Added support for binding in HTML format forms, including the bind, bindAttribute, and bindOnLoad, and onBindError attributes.
  • Added support for tool tips in HTML format forms, including the sourceForTooltip attribute.

ColdFusion MX 7:

  • When populating a cfselect tag with a query when the database field has spaces instead of a value, the error processing of the cfform tag required field is not triggered as it was in ColdFusion MX 6.1.
  • Added support for specifying multiple values to the selected attribute.
  • Deprecated the passthrough attribute. The tag now supports all HTML select tag attributes directly.
  • Added on-prefixed attributes.
  • Added enabled, group, height, label, queryPosition, tooltip, visible, and width attributes.


The following table lists attributes that ColdFusion uses directly. The tag also supports all HTML select tag attributes that are not on this list, and passes them directly to the browser.


Attributes that are marked as Flash only are not handled by the skins provided with ColdFusion. They are, however, included in the generated XML.








Name of the select form element.


Optional; HTML


A bind expression that dynamically sets an attribute of the control. For details, see Usage.



Populate the options

Specifies the HTML tag attribute whose value is set by the bind attribute. You can only specify attributes in the browser's HTML DOM tree, not ColdFusion-specific attributes.
Ignored if there is no bind attribute.




A Boolean value that specifies whether to execute the bind attribute expression when first loading the form. Ignored if there is no bind attribute.



Value of value attribute

Query column to use for the display label of each list element. Used with the query attribute.


Optional; Flash


Boolean value specifying whether you can edit the contents of the control.


Optional; Flash


Boolean value specifying whether the control is enabled. A disabled control appears in light gray. The inverse of the disabled attribute.


Optional; HTML and XML


Query column to use to group the items in the drop-down list into a two-level hierarchical list.


Optional; Flash


The height of the control, in pixels.



Value of name attribute

The HTML ID of the control.


Optional;Flash and XML


Label to put next to the control on a Flash or XML-format form.




Message to display if required = "yes" and no selection is made.




  • yes: allows selecting multiple elements in drop-down list.
  • no



See Description

The name of a JavaScript function to execute if evaluating a bind expression results in an error. The function must take two attributes: an HTTP status code and a message. (The status code is1 if the error is not an HTTP error.)If you omit this attribute, and specified a global error handler (by using the ColdFusion.setGlobalErrorHandler function), it displays the error message; otherwise a default error pop-up appears.




JavaScript (HTML/XML) or ActionScript (Flash) to run when the control changes due to user action.


Optional; HTML and XML


JavaScript to run when the user clicks the control.


Optional;HTML and XML


Custom JavaScript function to execute if validation fails.




JavaScript (HTML/XML) or ActionScript (Flash) to run when the user presses a keyboard key in the control.




JavaScript (HTML/XML) or ActionScript (Flash) to run when the user releases a keyboard key in the control.




JavaScript (HTML/XML) or ActionScript (Flash) to run when the user releases a mouse button in the control.




JavaScript (HTML/XML) or ActionScript (Flash) to run when the user presses a mouse button in the control.




Name of query to populate drop-down list.




If you populate the options list with a query and use HTML option child tags to specify additional entries, this attribute determines the location of the items from the query relative to the items from the option tags:

  • above: puts the query items above the options items.
  • below: puts the query items below the options items.




Note: This attribute has no effect if you omit the size attribute or set it to 1, because the browser always submits the displayed item. You can work around this issue: format forms by having an initial option tag with value=" " (notice the space character between the quotation marks). This workaround applies only for Flash forms and not for HTML forms or XML forms.

  • yes: a list element must be selected when the form is submitted.
  • no




One or more option values to preselect in the selection list. To specify multiple values, use a comma-delimited list. This attribute applies only if selection list items are generated from a query. The cfform tag preserveData attribute can override this value.




Number of entries to display at one time. The default value displays a drop-down list. Any other value displays a list box with size number of entries visible at one time.


Optional; HTML


The URL of a page to display as a tool tip. The page can include CFML and HTML markup to control the tip contents and format, and the tip can include images.
If you specify this attribute, an animated icon appears with the text "Loading..." while the tip is being loaded.




In HTML or XML format forms, ColdFusion passes the style attribute to the browser or XML.
In Flash format, must be a style specification in CSS format, with the same syntax and contents as used in Flex for the corresponding Flash element.


Optional; Flash, HTML


Text to display when the mouse pointer hovers over the control. The text can include HTML markup.
Ignored if you specify a sourceForTooltip attribute.




Query column to use for the value of each list element. Used with the query attribute.


Optional; Flash


Boolean value that specifies whether to show the control. The display reserves empty space for an invisible control.


Optional; Flash


The width of the control, in pixels.


For this tag to work properly. the browser must have JavaScript enabled. 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 tag 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 yes and the form posts back to the same page, and if the control is populated by a query, the posted selections 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 tags.
The group option generates a query by using SQL GROUP BY syntax and places the value column entries from each group in an indented list under the group column's 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.
The bind attribute lets you set cfselect attributes dynamically. Often, it is used to dynamically create the options list based on values that the user enters in the form. For example, you can use the bind attribute to create a Cities option list based on the user's selection from a States cfselect control. When you use a bind attribute to populate the selection list, the function or URL that returns the selection values must return one of the following:

  • A two-dimensional array, where the first element in each array row is the option value and the second element in the row is the text to display in the option list.
  • If the bind specifies a CFC function, a query, or, if the bind specifies a URL, a JSON representation of a query. The query must include columns whose names are the values of the cfselect tag value and display attributes. Although you can return additional columns, you cannot use them in your client-side code. When you call a CFC function, you do not have to convert the query to JSON format yourself; ColdFusion automatically does the conversion.
    To use this format, specify a value attribute. If you omit the display attribute, you must have only a single column in the query that contains the values; the values are also used as the displayed text.
    For detailed information on binding, see Binding data to form fields in the Developing ColdFusion Applications. For more information, see the cfform tag entry.


Example 1: Without data bindingThe 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 employee's e-mail 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"
    SELECT Emp_ID, EMail, Phone, Department, FirstName, LastName,  
        FirstName ||' '
||lastName as Name 
    FROM Employees  
    GROUP BY Department, Emp_ID, EMail, Phone, FirstName, LastName, FirstName 
<h2>cfselect Example</h2> 
<!-- The cfif statement is true if the form was submitted. 
    Show the selected names. ---> 
<cfif IsDefined("form.employeeid")> 
    <!--- The form was submitted. ---> 
    <h3>You Selected the following employees</h3> 
    <cfif form.employeeid IS ""> 
        <!--- Select All option was selected. Show all employees. ---> 
        <cfoutput query="GetAllEmployees"> 
            Email: #email#<br><br> 
            Use a query of queries to get the data for the selected users.  
            Form.employeeid is a comma-delimited list of selected employee IDs.  
        <cfquery name = "GetSelectedEmployees" dbtype="query"> 
            SELECT Emp_ID, EMail, Phone, Department, FirstName, LastName, 
||' ' ||lastName as Name 
            FROM GetAllEmployees 
            WHERE Emp_ID in (#form.employeeid#) 
        <!--- Display the names and e-mail addresses from the query. ---> 
        <cfoutput query="GetSelectedEmployees"> 
            #firstName# #lastName#<br> 
            Email: #email#<br> 
<!--- The cfform tag posts back to the current page. ---> 
<h3>Select one or more employees</h3> 
<cfform action = "#CGI.SCRIPT_NAME#"> 
            Use cfselect to present the query's LastName column,  
            grouped by department.  
            Allow Multiple selections. 
        name = "employeeid" 
        size = "15" 
        required = "Yes"
        message = "Select one or more employee names" 
        query = "GetAllEmployees" 
        display ="name" 
        value ="emp_id" 
        <!--- Add an option to select all employees. ---> 
        <option value = "">Select All</option> 
    <input type="Submit"> 

Example 2: With data bindingThe following example uses binding to fill in the options list of the Cities control only after the user selects a state. (In this example, only two states, California and New Jersey, have city entries.)The CFML page is the simplest part of the example. It consists of the following lines:

<cfform name="mycfform"> 
        The States selector.  
        The bindonload attribute is required to fill the selector.  
    <cfselect name="state" bind="cfc:bindFcns.getstates()" bindonload="true"> 
        <option name="0">--state--</option> 
    <cfselect name="city" bind="cfc:bindFcns.getcities({state})"> 
        <option name="0">--city--</option> 

The BindFcns CFC has three functions: getstates, to get the states; getcities, to get the cities; and an internal getXmlData function that parses an XML file to get the state and city information. The following examples shows the CFC:

    <cffunction name="getXmlData" output="true"> 
        <cfset var xmlData = "">  
        <cffile action="read" file="#expandpath('.')#\states.xml"
        <cfset xmlData = XmlParse(xmlData)> 
        <cfreturn xmlData> 
    <cffunction name="getstates" access="remote"> 
        <cfset state = arraynew(2)> 
        <cfset xmlData = getXmlData()> 
        <cfset numStates = 0> 
        <cfset state[1][1] = "0"> 
        <cfset state[1][2] = "--state--"> 
        <cfset numStates = ArrayLen(xmlData.states.XmlChildren)> 
        <cfloop from="1" to="#numStates#" index="j"> 
            <cfset state[j+1][1] =  
            <cfset state[j+1][2] = ltrim(xmlData.states.state[j].name.xmlText)> 
        <cfreturn state> 
    <cffunction name="getcities" access="remote"> 
        <cfargument name="state" required="yes"> 
        <cfset var city = arraynew(2)> 
        <cfset var xmlData = getXmlData()> 
        <cfset var numStates = 0> 
        <cfset var numCities = 0> 
<cflog text="In getcities"> 
        <cfset city[1][1] = "0"> 
        <cfset city[1][2] = "--city--"> 
            <cfset numStates = ArrayLen(xmlData.states.XmlChildren)> 
            <cfloop from="1" to="#numStates#" index="j"> 
                <cfif xmlData.states.state[j].XmlAttributes.abr eq state> 
                    <cfset numCities = 
                    <cfloop from="1" to="#numCities#" index="k"> 
                        <cfset city[k+1][1] =    ltrim(xmlData.states.state[j][k]> 
                        <cfset city[k+1][2] = ltrim(xmlData.states.state[j][k]> 
        <cfcatch type="any"> 
            <!--- Do nothing. ---> 
        <cfreturn city> 

The states.xml file has the following code. To keep the code short, only two states have cities, and only four states are listed.

    <state abr="NJ"> 
        <name>New Jersey</name> 
            <city name="Edison" /> 
            <city name="Rahway" /> 
            <city name="Atlantic City" /> 
            <city name="Hoboken" /> 
            <city name="Jersey City" /> 
            <city name="Newark" /> 
            <city name="Trenton" /> 
            <city name="Union City" /> 
    <state abr="CA"> 
            <city name="Anaheim" /> 
            <city name="Beverly Hills" /> 
            <city name="Elk Grove" /> 
            <city name="Fairfield" /> 
            <city name="Fremont" /> 
            <city name="Indian Wells" /> 
            <city name="Long Beach" /> 
    <state abr="ME"> 
    <state abr="MA"> 
Adobe logo

Sign in to your account