|
Posted by J.O. Aho on 10/09/11 11:32
Stefan Mueller wrote:
>>> var MyJSVariable = <? echo $MyPHPVariable; ?>;
>>> I guess that '<? echo $MyPHPVariable; ?>' gets translated to nothing
>>> because
>>> my PHP variable is empty at the beginning:
>> Yeah, you are right.
>> Now you have set the value for the variable, but it will only affect
>> things
>> that are done after this stage.
>
> Does that mean that it's not possible to transfer a value of a PHP variable
> to a JavaScript variable? The JavaScripts are defined in the header part and
> at this stage all the PHP variables are empty.
>
> Does that mean that it's not possible to do some checks while generating the
> page with PHP, so I can evaluate these results within a JavaScript?
> Stefan
>
>
You can store all PHP output to a variable and when you have made all the PHP
calculations and outputs, you just echo the stuff out in the right order.
<?PHP
/* do all calculations */
?>
<html>
<!-- make our HTML stuff here, including the output of data generated by PHP -->
<head>
<script type = "text/javascript">
function PageIsLoaded() {
var MyJSVariable = <? echo $MyPHPVariable; ?>;
alert(MyJSVariable);
}
</script>
</head>
<body>
<? echo $phpoutput; ?>
</body>
</html>
That wasn't that difficult, was it?
//Aho
Navigation:
[Reply to this message]
|