Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Katy, TX
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Clear textarea OnFocus?

    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.
    -Jeff

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Northern California
    Posts
    50
    Thanks
    2
    Thanked 0 Times in 0 Posts
    try this....
    <textarea cols="15" rows="15" name="testing" onFocus="this.value=''">This is a testing area.</textarea>

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Katy, TX
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    -Jeff

  • #4
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    try this:
    onFocus="if (this.value == this.defaultValue) { this.value = ''; }"
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •