tags:

views:

41

answers:

2

Hi

How can I set the text of a textarea object in PHP, is it necessary to use javascript.

I want to have one textarea, and be able to set the text that is displayed at different times.

Thanks

+1  A: 

If you want to change the text after it has been downloaded by the client (for example, have the text change every five seconds or something), you must use javascript. PHP is only used for server-side generation of the markup that the client downloads.

Ian Henry
+2  A: 
<textarea rows="2" cols="20">
<?php echo "Your text here. This can be dynamically created with PHP
when the page is served."; ?>
</textarea>

So, the textarea can be filled with PHP, but if you want to change the textarea after the page has loaded.... once it's out of the hands of the server, then you have to use Javascript.

Peter Ajtai
And please add `htmlspecialchars()` around the text in case there are some HTML tags in the echoed text.
shamittomar
@shamittomar - Inside a `textarea` everything is displayed literally, including html tags, so `htmlspecialchars()` is not required. - http://codepad.viper-7.com/QIjTI5
Peter Ajtai