CFLib.org – Common Function Library Project

jsFormat(mystring)

Last updated May 9, 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"); 
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson