SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Birmingham UK
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using JavaScript to empty a textarea

    I've got a textarea with the following content in:

    myname@website.com
    anothername@website.com

    What I want to do is empty the text area when the focus is on it, but only if the value is of that above. If the user has already edited the text area and focuses on it again, it shouldn't empty the area.

    Any ideas?

    Si

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Penns Woods
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Way Cool...

    <input type="text" name="T1" size="30" value="myname@website.com" onFocus="if(this.value=='myname@website.com')this.value=''; maxLength="50">

    This would be nice on SitePoint's Login ... <input type="text" name="T1" size="30" value="Unregistered" onFocus="if(this.value=='Unregistered')this.value=''; maxLength="50">
    // PS! My brain just hit a bad sector...

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Birmingham UK
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for that.

    I know how to do it with a single line text input (the one you've demonstrated), but I'm having troubles with multi line inputs (ie. textarea).
    How do you say if a value = "myname@website.com
    anothername@website.com" where there is a carriage return in between the two values?

    Any more ideas?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Penns Woods
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wild Guess...

    <input type="text" name="T1" size="30" value="myname@website.com&amp#13;anothername@website.com" onFocus="if(this.value=='myname@website.com&amp#13;anothername@website.com')this.value=''; maxLength="50">
    // PS! My brain just hit a bad sector...

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Penns Woods
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    This works...

    Sorry, I didn't pick up on the "textarea", must've been daydreaming...

    <html>
    <head>
    <title>textarea</title>
    <script>
    function swap(){
    set0.style.display='none';
    set1.style.display='';
    }
    </script>
    </head>

    <body>
    <form>
    <div id="set0" style="display:''">
    <textarea rows="5" cols="30" onFocus="swap()">myname@website.com&amp#13;anothername@website.com</textarea>
    </div>
    <div id="set1" style="display:'none'">
    <textarea rows="5" cols="30"></textarea>
    </div>
    </form>
    </body>
    </html>
    // PS! My brain just hit a bad sector...

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use a regular expression with \n\r
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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