SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Default value in form input field

    Hi,

    I have a simple newsletter subscription form on my site. I have set the default value to "name@email.de". How can I get this value to disappear once a user clicks on it?? Here's the code:

    Code:
    <form action="some_action" method="post">
    <input type="text" value="name@email.de" id="email" name="email" />
    <input type="submit" value="Bestellen" />
    </form>
    Any ideas? Do I need JavaScript for this? Cheers.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, it's javascript.
    Nasty inline way:
    Code:
    <input type="text" value="name@email.de" onfocus="this.value='';" id="email" name="email" />
    Nice unobtrusive way in external JS file:
    Code:
    window.onload = function() {
      document.getElementById('email').onfocus = function() {
        this.value = '';
      }
    }

  3. #3
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works great! Thanks a lot!!

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just out of curiosity, which one did you go with?

  5. #5
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like to keep all my Javascript in an external file...
    You can see it here. Thanks again for your help!

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Good stuff.

    And you're welcome.


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
  •