User Guide

Table Of Contents
628 Chapter 26: Introduction to Retrieving and Formatting Data
name="SelectedDepts"
value="2">
Marketing<br>
<cfinput type="checkbox"
name="SelectedDepts"
value="3">
HR<br>
<cfinput type="checkbox"
name="SelectedDepts"
value="4">
Sales<br>
</html>
The user sees the name of the department, but the value attribute of each check box is a number
that corresponds to the underlying database primary key for the department’s record.
If the user checks the Marketing and Sales items, the value of the SelectedDepts form field is 2,4
and you use the SelectedDepts value in the following SQL statement:
SELECT *
FROM Departmt
WHERE Dept_ID IN ( #Form.SelectedDepts# )
The ColdFusion server sends the following statement to the database:
SELECT *
FROM Departmt
WHERE Dept_ID IN ( 2,4 )
Handling string values
To search for a database field that contains string values (instead of numeric), you must modify
the
checkbox and cfquery syntax to make sure that the string values are sent to the data source
in single-quotation marks (').
The first example searched for department information based on a numeric primary key field
called Dept_ID. Suppose, instead, that the primary key is a database field called Dept_Name that
contains string values. In that case, your code for check boxes should look like the following:
<cfinput type="checkbox"
name="SelectedDepts"
value="Training">
Training<br>
<cfinput type="checkbox"
name="SelectedDepts"
value="Marketing">
Marketing<br>
<cfinput type="checkbox"
name="SelectedDepts"
value="HR">
HR<br>