How can I convert ColdFusion variables into JavaScript variables?

Use the toScript() function to create JavaScript variables from a ColdFusion variable. This function can convert ColdFusion strings, numbers, arrays, structures, and queries to JavaScript syntax that defines equivalent variables and values.

<cfset thisString="hello world">
<script type="text/javascript" language="JavaScript">
      var #toScript(thisString, "jsVar")#;
When ColdFusion runs this code, it sends the following to the client:
<script type="text/javascript" language="JavaScript">
   var jsVar = "hello world";

This question was written by Jeremy Petersen
It was last updated on March 23, 2006.




comments powered by Disqus