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 rich on 10/10/71 11:32

In article <dlnins$4u9$1@news.imp.ch>, Stefan Mueller says...
>
>>> 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
>
>

The PHP code is parsed by the server so by the time it reaches the web browser
it's only HTML and/or Javascript code. You can use PHP to make the HTML and
Javascript content dynamic by starting your document off with PHP, then adding
your PHP variables to your Javascript and HTML. As an example...


<?php
$testing = 'Testing PHP variable';
?>
<html>
<head>
<script language="javascript">
<!--
alert("<?=$testing?>");
//-->
</script>
</head>
<body>
<?=$testing?>
</body>
</html>

Whatever value you assign to "$testing" would appear in the Javascript alert
popup and also display in the web page. You'd basically use PHP to generate the
HTML/Javascript text that is sent to the requesting web browser. When you view
the HTML source, you won't see any references to PHP variables since those were
already processed by the server like they are suppose to.

Rich
--
Newsguy -- http://newsguy.com

 

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

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