28
Chapter 2: CFML Basics
Using the cfelseif tag to evaluate multiple expressions
To evaluate multiple expressions in a
cfif
statement, you can use
cfelseif
and
cfelse
tags in
your statement; for example:
<cfif
expression 1
>
HTML and CFML tags executed if expression 1 is True.
<cfelseif
expression 2
>
HTML and CFML tags executed if expression 2 is True.
<cfelse>
HTML and CFML tags executed for expression(s) that is False.
</cfif>
The following example shows you how you can evaluate multiple expressions using these tags.
This example uses a form in which users can enter their state to determine their state tax:
<cfoutput>
<cfif form.state IS "MA">
#form.state# State Tax: 8.5%
<cfelseif form.state IS "VA">
#form.state# State Tax: 8.2%
<cfelse>
#form.state# State Tax Unknown
</cfif>
</cfoutput>
The output of this
cfif
statement is based on the value entered by the user. If the user enters MA
in the state form field, the state tax results returned is 8.5%. If the user enters VA in the state form
field, the state tax results returned is 8.2%. If the user enters any other state in the state form field,
State Tax Unknown is returned.
Processing form data
Virtually all web applications that gather and write information to a database use a form to
accomplish that task. Forms let you collect information from a user (using an order form,
registration form, and so on) and write that information to a database. Like HTML, there are two
independent steps for creating a form in ColdFusion:
1.
Creating the layout for the form itself.
2.
Writing the code to process the submitted information.
Every form that you create in ColdFusion consist of two parts: the form page and the action page.
These two pages work together to process user input. The
form page
contains the user interface
elements, such as input fields and radio buttons. The
action page
handles the processing of the
form page data.
Summary of Contents for COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Page 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Page 6: ...6 Contents...
Page 10: ......
Page 14: ...14 Chapter 1 Introducing ColdFusion MX...
Page 38: ...38 Chapter 3 Database Fundamentals...
Page 40: ......
Page 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Page 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Page 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Page 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Page 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...