Posted By

riddla on 02/02/11


Tagged

form javascript html default input forms Value field defaultvalue


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

riddla
virendrakryadav


Default value for input fields (jQuery version)


 / Published in: jQuery
 

  1. var elem = $(':text');
  2.  
  3. // delete default value on focus
  4. elem.focus(function()
  5. {
  6. if ( this.value == this.defaultValue )
  7. {
  8. this.value = '';
  9. }
  10. });
  11.  
  12. // regain default value on blur
  13. elem.blur(function()
  14. {
  15. if ( this.value == '' )
  16. {
  17. this.value = this.defaultValue;
  18. }
  19. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Entherman on May 22, 2011

Thank you! Found good use of this, as I am a total beginner (if even I can be called that) in jQuery!

You need to login to post a comment.