Entry
How to pass the PHP variable to Javascript?
Sep 18th, 2002 10:33
Jeffrey Lake, Mohammed Ismail,
I came accross this problem recently, and I'm pretty sure there is a
proper answer out there somewhere. While you waiting, this may
interest you:
<?php
...[somehow your php generates a $php_variable here]
print "
<SCRIPT LANGUAGE=Javascript>
var javascript_variable = $php_variable;
";
...
?>
...[rest of Javascript stuff as normal]
</SCRIPT>
Yes, I've actually printed the Javascript code as if it were HTML, and
yes it does actually run exactly as if you had hardcoded the variable
into the Javascript.