Reply to Re: How to add some text to an input box with PHP

Your name:

Reply:


Posted by J.O. Aho on 10/10/45 11:32

Stefan Mueller wrote:
>>> I've an input box like
>>> <input type = "hidden" name = "MyBox" value = "">
>>>
>>> Now I'd like to add some text to this input box with PHP.
>>> How can I do that?
>> <input type = "hidden" name = "MyBox" value = "<? echo $MyValue; ?>">
>
> Actually I'm looking for a solution to add some text to an input box which
> already exists.
> In JavaScript I do it with
> document.MyForm.MyBox.value = "some text";
>
> But how can I do that within PHP?

Difference here is that PHP is a serverside script and JavaScript is a
clientside script, everything that PHP does has happen already when it's
displayed on your browser and can't do anything until you send the data back
to the server and let PHP process the data and send a new HTLM page to you.
JavaScript is something that runs in your browser and can be affected by
things you do on your browser.

So if you want a text appear depending what you do in another part of the
form, then you have to use clientside scripts and the solution would be to use

document.MyForm.MyBox.value = "some text";



> PS: To transfer the content of a PHP variable to a JavaScript variable with
> $MyJSVariable = <?echo $MyPHPVariable; ?>
> doesn't work. Mozilla Firefox's JavaScript Console says syntax error at '<?'
> I've to do that within JavaScript. Correct? I'm a little bit surprised why
> your JavaScript variable has a '$' at the beginning.

var MyJSVariable = <? echo $MyPHPVariable; ?>;

The page has to be PHP (ending with a .php) and your webserver must support
PHP and process the page (when you look at the page, there shouldn't be any
visible PHP code).

You can't just load the page in your browser from your hard drive and think
that the PHP will magically process the PHP-code on that file.


//Aho

[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

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