-----------------------------------------------------------------------
FAQ Topic - How do I get a jsp/php variable into
client-side javascript?
-----------------------------------------------------------------------
Use a server-side language to generate the javascript.
Certain characters of ECMAScript strings must be escaped by backslash.
These include quote marks, backslash, and line terminators.
JSP Example, using Apache Commons: `org.apache.commons.lang.StringEscapeUtils`:
var jsVar = "<%= StringEscapeUtils.escapeJavaScript(str) %>";
PHP example using `addcslashes`:
var jsVar = "<?php echo addcslashes($str,"\\\'\"\n\r"); ?>";
<URL:
http://jibbering.com/faq/example/addcslashes.php>
<URL:
http://php.net/manual/en/function.addcslashes.php>
<URL:
http://commons.apache.org/lang/>
The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/
--
The sendings of these daily posts are proficiently hosted
by
http://www.pair.com.