John Smith wrote:
[repaired quotation]
| 4.18 How do I get a perl/asp/php variable into client-side js?
|
| You have the serverside language generate the javascript:
|
| jsvar="<%= aspvar %>";
| jsvar="<?php echo $phpvar ?>";
<FAQENTRY>
Variables should be declared always, therefore it should be
var jsvar="<%= aspvar %>";
var jsvar="<?php echo $phpvar; ?>";
</FAQENTRY>
[...]
the first jsvar is for ASP (VB Script); the 2nd jsvar is for PHP.
what if I need to store a Perl/CGI variable into jsvar?
Then you use the means of the available programming language/environment.
Perl:
print "var jsvar='$perlvar';\n";
# Here-document syntax
print <<EOT
var jsvar="$perlvar";
EOT
POSIX 1003.2 compatible:
echo "var jsvar='$shellvar';";
printf "var jsvar='$shellvar';\n";
It really is pretty basic stuff in any programming language. Hopefully you
got the idea now.
Please ask language-related questions in the appropriate newsgroup, and use
a quote character prefix, preferably "| ", when you quote from third-hand
sources such as the FAQ.
PointedEars