You are here: Re: How to add some text to an input box with PHP « All PHP « IT news, forums, messages
Re: How to add some text to an input box with PHP

Posted by J.O. Aho on 10/10/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]


Удаленная работа для программистов  •  Как заработать на 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

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