Dynamically Populating List Boxes - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

Code
<cfloop index="Myindex" from="1"
to="10" step="1">
<cfloop index="randomindex"
from="1" to="100000" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
Magic number number #Myindex#
is:&nbsp;&nbsp;#RandRange
(100000,999999)#<br><br>
</cfoutput>
</cfloop>

Dynamically populating list boxes

In
"Form controls" on page
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:
Use the
cfquery
Use the
cfoutput
the
of this form control.
options
To dynamically populate a list box:
Open the file formpage.cfm.
1
Modify the file so that it appears as follows:
2
<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
574
Chapter 26: Retrieving and Formatting Data
561, you hard-coded a form's list box options. Instead of manually
tag to retrieve the column data from a database table.
tag with the
attribute within the
query
Description
Generates and displays 10 random numbers. This
code uses two loops. The outer loop repeats ten
times, once for each number to display. The inner
loop uses the
function to create another delay
Rand
by generating more (unused) random numbers. It
then calls the
RandRange
digit random number for display.
select
function to generate a six-
tag to dynamically populate

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents