Posted by J.O. Aho on 10/10/40 11:32
Stefan Mueller wrote:
> I try the following code on my PHP server but the browser says syntax error
> in 'var MyJSVariable = ;'
> I guess that '<? echo $MyPHPVariable; ?>' gets translated to nothing because
> my PHP variable is empty at the beginning:
Yeah, you are right.
> ==========================
> <html>
> <head>
> <script type = "text/javascript">
> function PageIsLoaded() {
> var MyJSVariable = <? echo $MyPHPVariable; ?>;
> alert(MyJSVariable);
> }
> </script>
> </head>
At this point $MyPHPVariable is empty and what you are doing is really
var MyJSVariable = ;
> <body onLoad = "PageIsLoaded()">
> <?php
> $MyPHPVariable = "some text";
> ?>
> </body>
> </html>
Now you have set the value for the variable, but it will only affect things
that are done after this stage.
//Aho
[Back to original message]
|