
731
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
Specifying the tree item in the URL
When a user clicks a tree item to link to a URL, the
cftreeItemKey
variable, which identifies the selected value, is
appended to the URL in the following form:
http://myserver.com?CFTREEITEMKEY=selected_item_value_attribute
If the value attribute includes spaces, ColdFusion replaces the spaces with plus characters (+).
Automatically passing the name of the selected tree item as part of the URL makes it easy to implement a basic “drill
down” application that displays additional information based on the selection. For example, if the specified URL is
another ColdFusion page, it can access the selected value as the variable
URL.CFTREEITEMKEY
.
To disable this behavior, set the
appendkey
attribute in the
cftree
tag to
no
.
Building drop-down list boxes
The drop-down list box that you can create in a
cfform
tag with a
cfselect
tag is like the HTML
select
tag.
However, the
cfselect
tag gives you more control over user inputs, provides error handling, and, most importantly,
lets you automatically populate the selection list from a query.
You can populate the drop-down list box from a query, or using lists of option elements created by the
option
tag.
The syntax for the
option
tag with the
cfselect
tag is the same as for the HTML
option
tag.
When you populate a
cfselect
tag with data from a query, you only need to specify the name of the query that is
supplying data for the
cfselect
tag and the query column name for each list element to display.
Populate a drop-down list box with query data using the cfselect tag
1
Create a ColdFusion page with the following content:
<cfquery name="getNames"
datasource="cfdocexamples">
SELECT * FROM Employee
</cfquery>
<cfform name="Form1" action="submit.cfm">
<cfselect name="employees"
query="getNames"
value="Emp_ID"
display="FirstName"
required="Yes"
multiple="Yes"
size="8">
</cfselect>
<br><input type="Submit" value="Submit">
</cfform>
Code
Description
href="http://www.adobe.com">
Makes the node of the tree a link.
href="http://www.adobe.com/devnet/mx/coldfu
sion/">
Makes the node of the tree a link.
Although this example does not show it, the
href
attribute can refer to the
name of a column in a query if that query populates the tree item.