User Guide
86 Chapter 6 Making Variables Dynamic
Note
In SQL, all strings must be surrounded in single quotes. The ListQualify function
returns a list with the specified qualifying character (here, a single quote) around
each item in the list.
If you select the second and fourth check boxes in the form, the following statement
gets sent to the database:
SELECT *
FROM Departmt
WHERE Dept_Name IN (’Marketing’,’Sales’)
Multiple selection lists
ColdFusion treats the result when a user selects multiple choices from a list box
(HTML input type
select with attribute multiple) just like results of selecting
multiple check boxes. The data made available to your page from any multiple
selection list box is a comma-delimited list of the entries selected by the user; for
example, a list box could contain the four entries: Training, Marketing, HR, and
Sales. If the user selects Marketing and Sales, the form field variable value is
Marketing,Sales.
You use multiple selection lists to search a database in the same way that you use
check boxes.
Searching numeric values
Suppose you want the user to select departments from a multiple-selection list box.
The query retrieves detailed information on the selected department(s):
Select one or more companies to get more information on:
<select name="SelectDepts" multiple>
<option value="1">Training
<option value="2">Marketing
<option value="3">HR
<option value="4">Sales
</select>
If the user selects the Marketing and Sales items, the value of the SelectDepts form
field is 2,4.
If this parameter is used in the following SQL statement:
SELECT *
FROM Departmt
WHERE Dept_ID IN (#form.SelectDepts#)
the following statement is sent to the database:
SELECT *
FROM Departmt
WHERE Dept_ID IN (2,4)