Results 1 to 3 of 3

Thread: How to blank out a text box onclick

  1. #1
    Join Date
    Feb 2009
    Posts
    2

    Default How to blank out a text box onclick

    I'm a newbie... and hopefully this is a simple thing to do. I want to put a text box on my HTML form that will have a default value of "Your Email" and when the user clicks into this text box, it will blank out the default value, allowing the user to enter his/her email address (without having to delete it first.)

    Is it possible to use the onclick for this? I need a code sample to see how to do this. Thank you in advance.!

  2. #2
    Join Date
    Jan 2008
    Location
    cardboard box
    Posts
    388

    Default

    The event you want is onFocus, which is when the element takes focus, of course. There are several different ways to select your text box other than clicking, such as tabbing or caret navigation.

    You can also use onBlur to refill the default value if the textbox is left blank, here's an example of the two in action:
    HTML Code:
    <script type="text/javascript">
    function blank(a) { if(a.value == a.defaultValue) a.value = ""; }
    function unblank(a) { if(a.value == "") a.value = a.defaultValue; }
    </script> 
    <input type="text" value="email goes here" onfocus="blank(this)" onblur="unblank(this)" />
    Have you tried turning it off and on again?

  3. #3
    Join Date
    Feb 2009
    Posts
    2

    Default Thank you!

    It works great! Thank you very much!

Posting Permissions

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