Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FAQ Topic - How do I get a jsp/php variable into client-side javascript? (2009-09-14)

0 views
Skip to first unread message

FAQ server

unread,
Sep 13, 2009, 7:00:02 PM9/13/09
to
-----------------------------------------------------------------------
FAQ Topic - How do I get a jsp/php variable into
client-side javascript?
-----------------------------------------------------------------------

Use the server-side language to generate the javascript:

// JSP
var jsvar = "${ jspVar }";
// PHP
var jsvar = "<?php echo $phpVar ?>";

If the string contains a quote mark, it will have to be escaped.
If the an inline-script tag is used, and the string must not
contains characters such as ` < `, ` > `, ` & `.


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.

kangax

unread,
Sep 13, 2009, 8:07:20 PM9/13/09
to
FAQ server wrote:
> -----------------------------------------------------------------------
> FAQ Topic - How do I get a jsp/php variable into
> client-side javascript?
> -----------------------------------------------------------------------
>
> Use the server-side language to generate the javascript:
>
> // JSP
> var jsvar = "${ jspVar }";
> // PHP
> var jsvar = "<?php echo $phpVar ?>";

// Ruby
var jsvar = "<%= rubyVar %>";

[...]

> If the an inline-script tag is used, and the string must not
> contains characters such as ` < `, ` > `, ` & `.

That sentence sounds strange. Maybe something like this is better:

"If inline script tag is used, the string must not contain characters
such as '<', '>' and '&'"

[...]

--
kangax

0 new messages