JSStringFormat

Returns a string that is safe to use with JavaScript.

Syntax

JSStringFormat(string)
string

Any string.

Usage

JSStringFormat escapes special JavaScript characters, such as the single quote ('), double quotes ("), and newline character so that you can put arbitrary strings safely into JavaScript.

Examples

<!-----------------------------------------------------------
  This example illustrates use of the JSStringFormat function. 
  ----------------------------------------------------------->
<HTML>
<HEAD>
<TITLE>JSStringFormat</TITLE>
</HEAD>

<BODY>
<H3>JSStringFormat</H3>

<CFSET stringValue = "An example string value with a tab chr(8)        , a 
newline (chr10)
and some ""quoted"" 'text'">

<P>This is the string we have created:<BR>
<CFOUTPUT>#stringValue#</CFOUTPUT>
</P>
<CFSET jsStringValue = JSStringFormat(#stringValue#)>

<!----------------------------------------------------------------------
Here we generate an alert from the JavaScript string jsStringValue.
----------------------------------------------------------------------->
<SCRIPT>
s="<CFOUTPUT>#jsStringValue#</CFOUTPUT>";
alert(s); 
</SCRIPT> 
</BODY>
</HTML> 


1