Dynamically Populating List Boxes - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

82

Dynamically Populating List Boxes

In Chapter 4, you hard-coded a form's list box options. Instead of manually entering
the information on a form, you can dynamically populate a list box with database
fields. When you 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:
To dynamically populate a list box:
1
2
Use the
tag to retrieve the column data from a database table.
cfquery
Use the
tag with the
cfoutput
dynamically populate the
Open the file formpage.cfm in ColdFusion Studio.
Modify the file so that it appears as follows:
<html>
<head>
<title>Input form</title>
</head>
<body>
<cfquery name="GetDepartments" datasource="CompanyInfo">
SELECT DISTINCT Location
FROM Departmt
</cfquery>
<!--- Define the action page in the form tag.
The form variables will pass to this page
when the form is submitted --->
<form action="actionpage.cfm" method="post">
<!-- text box -->
<p>
First Name: <input type="Text" name="FirstName" size="20"
maxlength="35"><br>
Last Name: <input type="Text" name="LastName" size="20"
maxlength="35"><br>
Salary: <input type="Text" name="Salary" size="10" maxlength="10">
</p>
<!-- list box -->
City
<select name="City">
<cfoutput query="GetDepartments">
<option value="#GetDepartments.Location#">
#GetDepartments.Location#
</option>
</cfoutput>
</select>
Chapter 6 Making Variables Dynamic
attribute within the
query
of this form control.
options
tag to
select

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion 5

Table of Contents