View Full Version : textarea's onfocus clears on edit

Aug 23rd, 2003, 08:32 AM
The user finds themselves on a page with instructions prepopulated within a textarea. When they focus on it, it clears via onfocus="this.value='';"
One problem...On the next page, they preview what they've typed with the option to return to the textarea and re-edit. When they do, they focus on the textarea and it unwantingly clears all they've typed.
Is there a way to clear the textarea only once onfocus or a better way to do this?

Aug 23rd, 2003, 11:09 AM
hm... why clear the textarea onfocus? I don't see the reason...

Aug 23rd, 2003, 07:27 PM
Umm...So the user can use it? :rolleyes:

Aug 24th, 2003, 12:12 AM
Perhaps, clearing the textarea only if its value contains nothing else...

hasty example:


<body onload="area.value=ival">

<textarea id="ta" onfocus="clearInst()" style="width:100%;height:200px"></textarea>

var ival = "text input instructions..."

var area = document.getElementById("ta");

function clearInst(){

if (area.value == ival){area.value = "";}


Aug 24th, 2003, 08:50 AM
Still not clearing...

function clear(){
var area = document.bob.comments;
if (area.value == area.defaultValue){area.value = "";}
<body onload="nut();ugh(); return true;">
<form name="bob">
<textarea name="comments" onfocus="clear();">Type your comments here</textarea>

Aug 24th, 2003, 07:30 PM
Lil' help?

Aug 24th, 2003, 11:08 PM
<script type="text/javascript">
message_var = false;

<textarea name="message" wrap="virtual" onfocus="this.value=(message_var == true) ? this.value : ''; message_var=true;">

Aug 25th, 2003, 01:44 AM

Aug 25th, 2003, 05:23 AM
Thanks fellers...Both work fine. :thumbsup:

Textareas behave weirdly...Formatting them even moreso.