Clear all default field values for inputs


/ Published in: jQuery
Save to your folder(s)

If included in a global javascript, whenever an input receives focus it will clear the default value. If the element loses focus without any user input then it will put the default value back in there. Useful for when you aren't using <label> and putting the label in the value of the text field instead.


Copy this code and paste it in your HTML
  1. $('input[type=text]').focus(function(){
  2. if (this.defaultValue==this.value){this.value = "";}
  3. });
  4. $('input[type=text]').blur(function(){
  5. if (this.value==""){this.value=this.defaultValue;}
  6. });

URL: http://www.golfnyguide.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.