CFScript

CFScript is a language within a language. CFScript is a scripting language that is similar to JavaScript but is simpler to use. Also, unlike JavaScript CFScript only runs on the ColdFusion Server; it does not run on the client system. A CFScript script can use all ColdFusion functions and all ColdFusion variables that are available in the script's scope.

CFScript provides a compact and efficient way to write ColdFusion logic. Typical uses of CFScript include:

The following sample script populates an array and locates the first array entry that starts with the word "key". It shows several of the elements of CFScript, including setting variables, loop structures, script code blocks, and function calls. Also, the code uses a cfoutput tag to display its results. While you can use CFScript for output, the cfoutput tag is usually easier to use.

<cfscript>
strings = ArrayNew(1);
strings[1]="the";
strings[2]="key to our";
strings[4]="idea";
for( i=1 ; i LE 4 ; i = i+1 )
{
  if(Find("key",strings[i],1))
    break; }
</cfscript>
<cfoutput>Entry #i# starts with "key"</cfoutput><br>

You use CFScript to create user-defined functions

For more information on CFScript, see Chapter 6, "Extending ColdFusion Pages with CFML Scripting". For more information on user-defined functions, see Chapter 9, "Writing and Calling User-Defined Functions".

Comments