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
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing default value from text box on click...

    Hey all

    I think this should be simple as ive seen it done many times.

    I have a text box for my mailing list, which displays "enter your email" in the box as default. But I want this text to disappear, leaving the box blank, when the user clicks inside it.

    This may be a javascript trick I suspect but either way if someone could show me how to clear the box when the user clicks into it, that would be great.

    Thanks

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're right in thinking you'll need Javascript.

    http://www.codeave.com/javascript/code.asp?u_log=7008

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Location
    Birmingham, MI
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is an example:
    Code:
    <script type="text/javascript">
       function valueFocus(e,d) {
          if(e.value == d) e.value = '';
       }
       function valueBlur(e,d) {
          if(e.value == '') e.value = d;
       }
    </script>
    Code:
    <input name="email" id="email" onfocus="valueFocus(this,'Enter Your Email');" onblur="valueBlur(this,'Enter Your Email');" value="Enter Your Email" />
    This way, if someone selects the input, enters nothing, then selects something else, 'Enter Your E-mail' will come back.

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Circusbred, that works perfectly!

    Thanks for the link Mark87, I used the example given but thanks for your help also


  •  

    Posting Permissions

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