Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 725

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Note: If the user does not select a check box or make a selection from a list box, no variable is created. The
tags do not work correctly if there are no values. To prevent errors, make the form fields required, use dynamic
cfupdate
SQL, or use the
tag to set a default value for the form field.
cfparam
Check boxes
When you place a series of check boxes with the same name in a form, the variable that is created contains a comma-
delimited list of values. The values can be either numeric values or alphanumeric strings. These two types of values are
treated slightly differently.
Handling numeric values
Suppose you want a user to select one or more departments using check boxes. You then query the database to retrieve
detailed information on the selected departments. The code for a simple set of check boxes that lets the user select
departments looks like the following:
<cfinput type="checkbox"
name="SelectedDepts"
value="1">
Training<br>
<cfinput type="checkbox"
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
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), modify the
syntax to make sure that the string values are sent to the data source in single-quotation marks (').
attribute of each check box is a number that corresponds to
value
Last updated 1/20/2012
and
cfinput
and
checkbox
cfquery
720

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents