Page 1 of 1

Textarea has no value attribute. So What to Do?

Posted: Wed Feb 14, 2007 9:12 pm
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>';

Posted: Wed Feb 14, 2007 9:40 pm
by nickvd

Code: Select all

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

Posted: Wed Feb 14, 2007 10:10 pm
by Kieran Huggins
you want the InnerHTML property of the textarea element

Posted: Wed Feb 14, 2007 10:26 pm
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.

That was easy.

Posted: Wed Feb 14, 2007 11:19 pm
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.