Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 723

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Dynamically populating list boxes
The code in
"Creating a basic
the information on a form, you can dynamically populate a list box with database fields. When you write code this way,
the form page automatically reflects the changes that you make to the database.
You use two tags to dynamically populate a list box:
• Use the
tag to retrieve the column data from a database table.
cfquery
• Use the
tag with the
cfselect
Dynamically populate a list box
Open the formpage.cfm page.
1
Modify the file so that it appears as follows:
2
<html>
<head>
<title>Input form</title>
</head>
<body>
<cfquery name="GetDepartments" datasource="cfdocexamples">
SELECT DISTINCT Location
FROM Departmt
</cfquery>
<!--- Define the action page in the form tag.
The form variables pass to this page
when the form is submitted --->
<cfform action="actionpage.cfm" method="post">
<!--- Text box. --->
<p>
First Name: <cfinput type="Text" name="FirstName" size="20" maxlength="35"><br>
Last Name: <cfinput type="Text" name="LastName" size="20" maxlength="35"><br>
Salary: <cfinput type="Text" name="Salary" size="10" maxlength="10">
</p>
<!--- List box. --->
City
<cfset optsize=getDepartments.recordcount + 1>
<cfselect name="City" query="GetDepartments" value="Location" size="#optsize#">
<option value="">Select All
</cfselect>
<!--- Radio buttons. --->
<p>
form" on page 704 hard-coded the form's list box options. Instead of manually entering
attribute to dynamically populate the
query
Last updated 1/20/2012
of this form control.
options
718

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents