Reply to Re: To pass a PHP variable to javascript

Your name:

Reply:


Posted by d on 10/12/88 11:38

"Pablito" <pablito@nonspam.com> wrote in message
news:EZ4Df.68327$eD5.1162011@twister2.libero.it...
>
> "jamen" <jamen@invalid> ha scritto nel messaggio
> news:43dcc9ca$0$2086$edfadb0f@dtext02.news.tele.dk...
>> Pablito wrote:
>> > can I pass a $var maked with PHP to javascript
>>
>> of course..
>>
>> <script type="text/javascript">
>>
>> var jsvar = <?php echo $phpvar ?>;
>>
>> </script>
>
> I thank you very much but my script is this and it is like your but do
> not
> work
> Why?
>
>
> <?php
> $cont=fopen('cont.txt','r');
> $incr=fgets($cont);
> //echo $incr;
> $incr++;
> fclose($cont);
> $cont=fopen('cont.txt','w');
> fwrite($cont,$incr);
> fclose($cont);
> echo "<script type="text/javascript">
> var incr=$incr
> </script>";
> ?>

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=javascript' in the script tag, too, just to be on the safe side ;)

How are you using that javascript variable?

> Pablito

dave

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация