Exercise 6: Dynamically Populating The List Of Event Types - MACROMEDIA COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX Getting Started

Building coldfusion mx applications
Table of Contents

Advertisement

To test the modified code:
View the tripedit.cfm page in a browser.
1.
Test the client- and server-side field validations by filling out the fields on the form and clicking
2.
Save.
Testing recommendations:
Omit required fields such as trip name or location.
Make the departure date an invalid date, such as 12/32/2002.
Enter a nonnumeric value in Number of People, such as one.

Exercise 6: Dynamically populating the list of event types

Currently, the event types in the tripedit.cfm file are hard-coded. In the preceding exercises, each
tag in the event type contained a
option
values come from the eventtypes table; they do not have to be hard-coded. The event type in the
Trips table is an identifier that is used as a foreign key to the eventtypes table, which holds the
actual event names. The eventtypes table column
and the
eventType
this table, you must include the following
<cfquery name="GetEvents" datasource="CompassTravel">
SELECT eventType, eventTypeID
FROM eventtypes
</cfquery>
To exploit the query in the HTML
tag.
cfselect
The
tag is an improved version of the HTML
cfselect
tags, the
cfselect
entered. Using the
field data entry as follows.
To display a list of event types from the eventtypes table and add validation:
View the tripedit.cfm page in a browser. Select the event types drop-down list. Notice that only
1.
three event types appear in the list.
Open the tripedit.cfm file in the my_app directory.
2.
Add the following code before the
3.
<cfquery name="GetEvents" datasource="CompassTravel">
SELECT eventType, eventTypeID
FROM eventtypes
</cfquery>
Note: In previous exercises, you learned to write structured reusable code by placing queries in
ColdFusion components. Although this practice is advisable when creating ColdFusion
applications, you put the query in the tripedit.cfm file for simplicity.
for the literal value that appears in the select box. To retrieve the data from
option
tag provides the
required
tag and the preceding
cfselect
<html>

Exercise 6: Dynamically populating the list of event types

attribute and option text, such as
value
eventTypeID
:
cfquery
tags, you can replace the HTML
select
and
attributes that validate the data
message
, you can implement the
cfquery
tag:
Surfing
is used for the
attribute
value
tag with a
select
tag. Like other ColdFusion form
eventType
. These
119

Advertisement

Table of Contents
loading

This manual is also suitable for:

Colfusion mx 7 - installing and using coldfusion mx

Table of Contents