Creates a JavaScript expression that assigns the value of a variable to a JavaScript variable. This function can convert strings, numbers, arrays, structures, and queries to JavaScript syntax that defines equivalent variables and values.

ToScript( cfvar=any, javascriptvar=string, outputformat=boolean, ASFormat=boolean );

Returns: String

Argument Description Default
any, required

A variable.

string, required

A string that specifies the name of the JavaScript variable that the ToScript function creates.

boolean, optional

A Boolean value that determines whether to create WDDX (JavaScript) or ActionScript style output for structures and queries. Default: true


boolean, optional

A Boolean value that specifies whether to use ActionScript shortcuts in the script. Default: false


	<cfset myArray=ArrayNew(1)>
	<cfloop index="i" from="1" to="4">
		<cfset myArray[i]="This is array element" & i>
	<b>The output of ToScript(myArray, "jsVar")</b><br>
	#ToScript(myArray, "jsVar")#<br>
	<b>In a JavaScript script, convert thisString Variable to JavaScript
	and output the resulting variable:</b><br>
	<script type="text/javascript" language="JavaScript">
			var #ToScript(myArray, "jsVar")#;
			for (i in jsVar) {
			document.write("jsVar in JavaScript is: " + jsVar[i] + "<br>");

See also