Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorcmac
    • CommentTimeFeb 26th 2006
     permalink
    I'm looking for a script that will clear a text field of it's default info with one click.
    For example if I had a contact form that wanted an email address, I'd have the value of the text fiend set to "Enter your email address". Then when the user clicked in the form field once, the text would dissappear all at once.
    • CommentAuthormariachi77
    • CommentTimeFeb 26th 2006
     permalink
    You could do something like:
    onfocus= 'if (this.value=="Enter your email address") this.value=""'

    However, adding this event handler inline is not very good design -- it might be a hassle but maybe you should write a function populates your form with the default values and then adds the onfocus event handler when the window loads. Remember to use the getElementbyId test to ensure the user has Javascript enabled.
    •  
      CommentAuthoranblik
    • CommentTimeFeb 26th 2006
     permalink
    Bobby will be happy :)
    •  
      CommentAuthornifkin
    • CommentTimeFeb 26th 2006
     permalink
    If you're up for playing with a speck of jQuery in the process I tossed together this example page that self-clears and refills if empty. But only when the field contains default content. So if someone has entered an address and clicks again it won't get wiped out. And without the inline JS. ;)
    • CommentAuthorLuc
    • CommentTimeMar 31st 2006
     permalink
    nifkin - that jQuery is a lifesaver! I've been looking for something like that for a while now, thanks for the tip-off.
Add your comments
    Username Password
  • Format comments as (Help)