CFLib.org – Common Function Library Project

jsFormat(mystring)

Last updated May 09, 2003

author

Isaac Dealey

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Extends the jsstringformat function and allows the string "</script>" to be embedded in a javascript literal string, preventing "unterminated string constant" errors in your javascript.

Return Values:
Returns a string.

Example:

<cfsavecontent variable="js">
<script>
alert('e');
</script>
</cfsavecontent>

<cfset js = jsFormat(js)>
<cfoutput>
<script>
var someval = '#js#';
</script>
</cfoutput>

Parameters:

Name Description Required
mystring String to format. Yes

Full UDF Source:

/**
 * Fixes an oversight in the jsstringformat() function
 * 
 * @param mystring      String to format. (Required)
 * @return Returns a string. 
 * @author Isaac Dealey (info@turnkey.to) 
 * @version 1, May 9, 2003 
 */
function jsFormat(mystring) {
    return Replace(jsstringformat(mystring),"/","\/","ALL"); 
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson