Using ColdFusion variable with line breaks in JavaScript -
i have text area accepts line breaks. content of text area saved in coldfusion variable (lets call #fieldval#). so, variable contents
textline 1 textline 2 later on, use variable in javascript
document.all.fieldname.value = "#fieldval#"; however, when javascript hits page, looks this:
document.all.fieldname.value = "textline 1 textline 2"; and script breaks because first line doesn't end in semicolon.
i tried setting javascript variable coldfusion text doing replace(), still hit same issue line not ending correctly.
i think i'm missing obvious not seeing it. can tell me i'm missing here?
use jsstringformat() function. designed escape meta characters in javascript
escapes special javascript characters, such single-quotation mark, double-quotation mark, , newline.
https://wikidocs.adobe.com/wiki/display/coldfusionen/jsstringformat
document.all.fieldname.value = "#jsstringformat( fieldval )#"; if you're using coldfusion 10+ or lucee server, use encodeforjavascript().
https://wikidocs.adobe.com/wiki/display/coldfusionen/encodeforjavascript
Comments
Post a Comment