Pablito ha scritto:[color=blue]
> Hi at all,
> can I pass a $var maked with PHP to javascript
> How?
> Thanks
> Pablito
>
>[/color]
Hi Pablito,
that's a simple example:
<?php
$a="Hallo";
echo "<script type=\"text/javascript\">
alert ('$a')
</script>";
?>
"jamen" <jamen@invali d> ha scritto nel messaggio
news:43dcc9ca$0 $2086$edfadb0f@ dtext02.news.te le.dk...[color=blue]
> Pablito wrote:[color=green]
> > can I pass a $var maked with PHP to javascript[/color]
>
> of course..
>
> <script type="text/javascript">
>
> var jsvar = <?php echo $phpvar ?>;
>
> </script>[/color]
I thank you very much but my script is this and it is like your but do not
work
Why?
"Pablito" <pablito@nonspa m.com> wrote in message
news:EZ4Df.6832 7$eD5.1162011@t wister2.libero. it...[color=blue]
>
> "jamen" <jamen@invali d> ha scritto nel messaggio
> news:43dcc9ca$0 $2086$edfadb0f@ dtext02.news.te le.dk...[color=green]
>> Pablito wrote:[color=darkred]
>> > can I pass a $var maked with PHP to javascript[/color]
>>
>> of course..
>>
>> <script type="text/javascript">
>>
>> var jsvar = <?php echo $phpvar ?>;
>>
>> </script>[/color]
>
> I thank you very much but my script is this and it is like your but do
> not
> work
> Why?
>
>
> <?php
> $cont=fopen('co nt.txt','r');
> $incr=fgets($co nt);
> //echo $incr;
> $incr++;
> fclose($cont);
> $cont=fopen('co nt.txt','w');
> fwrite($cont,$i ncr);
> fclose($cont);
> echo "<script type="text/javascript">
> var incr=$incr
> </script>";
> ?>[/color]
You need to escape the quotes in your <script> tag:
echo "<script type=\"text/javascript\">
var incr=$incr;
</script>";
(and note the semi-colon after the var line). You might also want to put
'language=javas cript' in the script tag, too, just to be on the safe side ;)
How are you using that javascript variable?
[color=blue]
> Pablito[/color]
This code doesn't make much sense. You must understand that PHP and
JavaScript are _not_ executed at the same time. PHP is parsed in the server
and it's used to create the JavaScript code. So, when you get JavaScript
errors, check first the generated code.
Also, your code should raise a PHP parse error. I guess your PHP install is
configured to hide errors. Edit php.ini and set accordingly the
error_reporting value.
Comment