PDA

View Full Version : textarea's onfocus clears on edit



zoobie
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?
Thanks
:p

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

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

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

hasty example:

<html>

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

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

<script>
var ival = "text input instructions..."

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

function clearInst(){

if (area.value == ival){area.value = "";}
}
</script>

</body></html>

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


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

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

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

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

cheesebag
Aug 25th, 2003, 01:44 AM
<textarea.......onfocus="if(this.value==this.defaultValue)this.value=''">

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

Textareas behave weirdly...Formatting them even moreso.