Building Drop-Down List Boxes  
 
 

The drop-down list box you can create with CFSELECT is a close relative of the HTML SELECT tag. CFSELECT gives you more control over user inputs, error handling, and allows you to populate the selection list from a query.

 
 
  Populating a CFSELECT with query data  
 
 

When you populate a CFSELECT with data from a query, you only need to specify the name of the query that is supplying data for the CFSELECT and the query column name for each list element you want to display.

 
 
  Example: Populate a CFSELECT from a data column:  
 
<CFQUERY NAME="myquery" 
    DATASOURCE="cfsnippets">
    SELECT * FROM Employees
</CFQUERY>

<CFFORM NAME="Form1" ACTION="submit.cfm" 
    METHOD="Post">

    <CFSELECT NAME="myselectbox"
        QUERY="myquery"
        VALUE="Employee_ID"
        DISPLAY="FirstName"
        REQUIRED="yes"
        MULTIPLE="yes"
        SIZE="8">
    </CFSELECT>

    <BR><INPUT TYPE="Submit" 
            VALUE="Submit">

</CFFORM>

The resulting drop-down list box looks like this:

Note that because the MULTIPLE attribute is used, the user can select multiple entries in the select box. When MULTIPLE is omitted or SINGLE is explicitly used and the SIZE attribute is set to zero, the resulting CFSELECT looks like this:

One other thing to note about this example: since the VALUE tag specifies the primary key for the Employee table, this data is used in the form variable that is passed to the application page specified in ACTION.



 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.