ToScript
889
Usage
To use a ColdFusion variable in JavaScript or ActionScript, the
ToScript
function must be in a
cfoutput
region and be surrounded by number signs (#). For example, the following code uses
the
ToScript
function to convert a ColdFusion variable to a JavaScript variable:
<cfset thisString="hello world">
<script type="text/javascript" language="JavaScript">
<cfoutput>
var #toScript(thisString, "jsVar")#;
</cfoutput>
</script>
When ColdFusion runs this code, it sends the following to the client:
<script type="text/javascript" language="JavaScript">
var jsVar = "hello world";
</script>
An HTML script tag must enclose the JavaScript code. The
cfoutput
tag does not need to be
inside the script block; it can also surround the block.
WDDX-style output generates JavaScript code that creates a WDDXRecordset object, where the
key of each record set entry is a column name, and the value of the recordlist entry is an array of
the corresponding query column entries, as follows:
WDDXQuery = new WddxRecordset();
col0 = new Array();
col0[0] = "John";
col0[1] = "John";
WDDXQuery["firstname"] = col0;
col0 = null;
col1 = new Array();
col1[0] = "Lund";
col1[1] = "Allen";
WDDXQuery["lastname"] = col1;
col1 = null;
To use WDDX-style output, you must first load the
cf_webroot
/CFIDE/scripts/wddx.js script,
which defines JavaScript WDDX objects, as in the following line:
<script type="text/javascript" src="/CFIDE/scripts/wddx.js script"> </script>
For more information on WDDX in JavaScript, see
Chapter 9, “WDDX JavaScript Objects,” on
page 1091
.
ActionScript-style output generates code that creates an array of objects, where the array is
indexed by row number, and the objects consist of column name - column value pairs, as follows:
ActionScriptQuery = new Array();
ActionScriptQuery[0] = new Object();
ActionScriptQuery[0]['firstname'] = "John";
ActionScriptQuery[0]['lastname'] = "Lund";
ActionScriptQuery[1] = new Object();
ActionScriptQuery[1]['firstname'] = "John";
ActionScriptQuery[1]['lastname'] = "Allen";
Summary of Contents for COLFUSION MX 7 - INSTALLING AND USING COLDFUSION MX
Page 1: ...COLDFUSION MX7 CFML Reference...
Page 20: ...20 Chapter 1 Reserved Words and Variables...
Page 50: ...50 Chapter 2 ColdFusion Tags cfelse br Searching cfif cfloop cfif...
Page 101: ...cfdefaultcase 101 cfdefaultcase cfswitch cfoutput Your grade is grade cfoutput...
Page 115: ...cfdocumentsection 115 cfdocumentsection cfoutput cfdocument...
Page 411: ...cftable 411 cftable body html...
Page 515: ...Chr 515 maxlength 5 p input type Submit name input type RESET cfform...
Page 605: ...GetEncoding 605 WriteOutput The encoding is theEncoding cfscript cfif...
Page 629: ...GetProfileString 629 tr td input type Submit name Submit value Submit td td td tr table form...
Page 655: ...IIf 655 cfoutput IIf Hour Now GTE 12 DE It is afternoon or evening DE It is morning cfoutput b...
Page 664: ...664 Chapter 3 ColdFusion Functions cfelse h3 Conversion error h3 cfif...
Page 687: ...IsStruct 687 cfoutput cfquery cfif cfoutput hr Employee Add Complete cfoutput cfcase cfswitch...
Page 751: ...LSDateFormat 751 hr noshade cfoutput cfloop...
Page 861: ...StructFind 861 cfquery cfif cfoutput hr Employee Add Complete cfoutput cfcase cfswitch...
Page 903: ...Val 903 value Is the beginning numeric name form...
Page 932: ...932 Chapter 3 ColdFusion Functions...
Page 944: ...944 Chapter 4 ColdFusion MX Flash Form Style Reference...
Page 962: ...962 Chapter 5 Application CFC Reference...
Page 1054: ...1054 Chapter 6 ColdFusion MX Event Gateway Reference...