Entry
How to change php variables to javascript variables?
Dec 15th, 2002 02:42
Dan Stockton, Mark O\'Malley,
I'm not 100% if this is what you're looking for! But this seems to allow
php variables to be assigned to javascript variables. Handy for
validation and the like.
<?
# php variable to javascript test
#$test = "hello"; # php variable
#echo "<script> var jstest = '$test'; </script>"; # Assign it to a
javascript variable
#echo "<script>document.write(jstest); </script>"; # print javascript
variable.
?>
_________________________________________________________
.. just another way to do the same thing-
<?$test='hello'?>
<script language="javascript" type="text/javascript">
var jstest='<?=$test?>';
document.write('jstest');
</script>
(maybe it's just coding preference but this one's compliant and
quicker:)