For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Introduction to Retrieving and Formatting Data / 

Creating dynamic check boxes and multiple-selection list boxes

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

When an HTML or CFML form contains a list of check boxes with the same name or a multiple-selection list box (that is, a box in which users can select multiple items from the list), the user's entries are made available as a comma-delimited list with the selected values. These lists can be useful for a wide range of input types.

Note: If the user does not select a check box or make a selection from a list box, no variable is created. The cfinput and cfupdate tags do not work correctly if there are no values. To prevent errors, make the form fields required, use dynamic SQL, or use the cfparam tag to set a default value for the form field.

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 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), 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>

<cfinput type="checkbox"
name="SelectedDepts"
value="Sales">
Sales<br>

If the user checked Marketing and Sales, the value of the SelectedDepts form field would be the list Marketing,Sales and you use the following SQL statement:

SELECT *
FROM Departmt
WHERE Dept_Name IN
(#ListQualify(Form.SelectedDepts,"'")#)

In SQL, all strings must be surrounded in single-quotation marks. The ListQualify function returns a list with the specified qualifying character (here, a single-quotation mark) 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

A multiple-selection list box is defined by a select or cfselect tag with a multiple or multipe="yes" attribute and a size attribute value greater than 1. ColdFusion treats the result when a user selects multiple choices from a multiple-selection list box like the 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 can use multiple-selection lists to search a database in the same way that you use check boxes.

Handling numeric values

Suppose you want the user to select departments from a multiple-selection list box. The query retrieves detailed information on the selected departments, as follows:

Select one or departments to get more information on:
<cfselect name="SelectDepts" multiple>
<option value="1">Training
<option value="2">Marketing
<option value="3">HR
<option value="4">Sales
</cfselect>

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)

Handling string values

Suppose you want the user to select departments from a multiple-selection list box. The database search field is a string field. The query retrieves detailed information on the selected departments, as follows:

<cfselect name="SelectDepts" multiple>
<option value="Training">Training
<option value="Marketing">Marketing
<option value="HR">HR
<option value="Sales">Sales
</cfselect>

If the user selects the Marketing and Sales items, the SelectDepts form field value is Marketing,Sales.
Just as you did when using check boxes to search database fields containing string values, use the ColdFusion ListQualify function with multiple-selection list boxes:

SELECT *
FROM Departmt
WHERE Dept_Name IN (#ListQualify(Form.SelectDepts,"'")#)

The following statement is sent to the database:

SELECT *
FROM Departmt
WHERE Dept_Name IN ('Marketing','Sales')

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices