Possible duplicate:
pass variable from php to js
This may seem trivial. I set the value of the PHP variable to false. Then, after some processing, I output some JavaScript variables in a script. This is the code
$a = true; $b = false; echo '<script type="text/javascript"> var a = '.$a.'; var b = '.$b.'; </script>';
When the script ends, I get this output:
var a = 1; var b = ;
So, I get a syntax error in JavaScript. Now the question is how to have these values ββas true Boolean values ββin JavaScript, huh?
Estimated Conclusion:
var a = true; var b = false;
I don't need strings like 'true'
or 'false'
... or 1 and 0, but only boolean true
and false
. Any help in this regard, as well as some explanation of why PHP behaves this way?
source share