You are here: Re: To pass a PHP variable to javascript « PHP Programming Language « IT news, forums, messages
Re: To pass a PHP variable to javascript

Posted by Alvaro G. Vicario on 10/08/43 11:38

*** Pablito escribió/wrote (Sun, 29 Jan 2006 15:14:44 GMT):
> <?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>";
> ?>

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.

Try this:

<?php
$cont=fopen('cont.txt','r');
$incr=fgets($cont);
//echo $incr;
$incr++;
fclose($cont);
$cont=fopen('cont.txt','w');
fwrite($cont,$incr);
fclose($cont);
?>
<script type="text/javascript"><!--
var incr=<?=$incr?>;
//--></script>

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.

--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--

 

Navigation:

[Reply to this 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

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