View Full Version : Clear textarea OnFocus?

07-24-2002, 06:37 AM
I have no clue how to use javascript, so I was hoping someone could help me out. Anyway, I have a textarea in a form, and I want to have some text typed in it. However, I want that text to automatically delete as soon as the person selects or clicks on the textarea (I think that's what you use OnFocus for). I did a tiny bit of research and it said that OnFocus used javascript commands, and I didn't see anything else that would clear the textarea when it was selected. So could someone tell me what code to put so that it will delete/clear/reset the contents of the textarea when someone selects it? Thanks.

07-24-2002, 06:51 AM
try this....
<textarea cols="15" rows="15" name="testing" onFocus="this.value=''">This is a testing area.</textarea>

07-24-2002, 07:32 AM
Thanks, that works, but now I've come up with something I haven't thought of before. What if I only want it to happen once? Err for example, let's just say they've clicked on the textarea and it's reset my message. They continue to type something, accidently click somewhere else, then click in the textarea again to continue typing and it resets that to. Is there a way to make it so that it only happens the first time they select the textarea?

07-24-2002, 10:25 AM
try this:
onFocus="if (this.value == this.defaultValue) { this.value = ''; }"

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum