March 29, 2006

How do I make sure a string is safe to use with JavaScript?

An article from coldfusion cookbook using jSStringFormat():

“If you are dynamically populating a JavaScript variable, you may find that your code breaks with “unterminated string constant” or similar error messages. This is probably a case of your JavaScript variables containing characters that are considers to be “special” characters by JavaScript. You will need to “escape” these special characters so that JavaScript can process them.”

© Michael Sharman 2017