Text field default that clears on click

Discussion in 'Web Design and Development' started by chainprayer, Apr 28, 2009.

  1. chainprayer macrumors 6502a

    Joined:
    Feb 10, 2008
    #1
    I'm trying to get a text field in an HTML form that has a default value (i.e. it says email address) but when a user clicks on it the form clears.

    I know how to make a default value, but the user has to manually clear the default before entering their info.

    Thanks!
     
  2. SelfMadeCelo macrumors regular

    SelfMadeCelo

    Joined:
    Sep 9, 2008
    Location:
    Tulare, CA
    #2
    Javascript. Try this.

    Code:
    onFocus="this.value=''"
    So it would look like this:

    Code:
    <input type="text" onFocus="this.value=''" value="Email address here">
     
  3. chainprayer thread starter macrumors 6502a

    Joined:
    Feb 10, 2008
  4. Melrose macrumors 604

    Melrose

    Joined:
    Dec 12, 2007
    Location:
    Elsewhere
    #4
    Optionally, you can have it re-add the default text if the user hasn't entered anything:

    Code:
    <input type="text" onFocus="this.value='';" onBlur="if(this.value=='') {this.value='Email Address here';}" value="Email address here" />
    
     

Share This Page