Textarea has no value attribute. So What to Do?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SoreE yes
Forum Commoner
Posts: 32
Joined: Wed Oct 11, 2006 3:59 am

Textarea has no value attribute. So What to Do?

Post by SoreE yes »

Hi, The following code (extracted from my spagetti code) highlights my problem. I want to retain the contents of the 'Comment' file upon submission, but in HTML there is no 'value' attribute for the TEXTAREA, so what to do? I found another similar posting on this site, but it gives a Javascript solution. I'd rather use server side coding. Your time much appreciated.

Code: Select all

if (!isset($_POST['Title'])) $_POST['Title'] = '';
if (!isset($_POST['Comment'])) $_POST['Comment'] = '';
	
    echo '<form action="'.htmlspecialchars($_SERVER['PHP_SELF']).'" method="post">';
	echo 'Title:</td><td><input type="text" name="Title" value="'.htmlspecialchars($_POST['Title']).'"></BR>';
    echo 'Comment:</td><td><textarea name="Comment" cols="25" rows="5" ></textarea>';
	echo '<input type="submit" value="Submit" name="submit">';
	echo '</form>';
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Code: Select all

<textarea>This text is inside the textarea</textarea>
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you want the InnerHTML property of the textarea element
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

innerHTML is JS right?

Where ever you are getting the input from ($_POST, SQL, etc.) just place that in between the <textarea> tags.
SoreE yes
Forum Commoner
Posts: 32
Joined: Wed Oct 11, 2006 3:59 am

That was easy.

Post by SoreE yes »

nickvd wrote:

Code: Select all

<textarea>This text is inside the textarea</textarea>
.

Thanks, it worked fine. Funny, I had tried that at an earlier time and it didn't work.
Post Reply