![]() ![]() ![]() |
ColdFusion now has a server-side scripting language, CFScript, that offers ColdFusion functionality in script syntax.
This JavaScript-like language offers the same control flow, but without tags. CFScript regions are bounded by <CFSCRIPT> and </CFSCRIPT>. You can use ColdFusion expressions, but not CFML tags, inside a CFScript region.
See Chapter 2, Functions and Expressions for more on CFML expressions.
The following example shows how a block of CFSET tags can be rewritten in CFScript:
<CFSET employee=StructNew()> <CFSET employee.firstname=FORM.firstname> <CFSET employee.lastname=FORM.lastname> <CFSET employee.email=FORM.email> <CFSET employee.phone=FORM.phone> <CFSET employee.department=FORM.department> <CFOUTPUT>About to add #FORM.firstname# #FORM.lastname# </CFOUTPUT>
<CFSCRIPT> employee=StructNew(); employee.firstname=FORM.firstname; employee.lastname=FORM.lastname; employee.email=FORM.email; employee.phone=FORM.phone; employee.department=FORM.department; WriteOutput("About to add " & FORM.firstname & " " & FORM.lastname); </CFSCRIPT>
The WriteOutput function appends text to the page output stream. Although you can call this function anywhere within a page, it is most useful inside a CFSCRIPT block. See the CFML Language Reference for information on the WriteOutput function.
CFScript supports the following statements:
The following JavaScript references may be useful in understanding the concepts and control flow statements in CFScript:
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.