Posted By

smoothdzion on 11/04/09


Tagged

javascript textmate input jquery Value label


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

smoothdzion
jannisg
broseff


jQuery - Add/Focus/Blur Input Value


 / Published in: jQuery
 

First value takes empty input values and adds 'Enter Value'. Second snippet removes 'Enter Value' when input is focused. Third snippet re-adds 'Enter Value' if the value is left blank.

  1. $(function(){
  2.  
  3. $('input[type="text"]').each(function(){
  4. if(this.value==''){this.value='Enter Value'}
  5. });
  6.  
  7. $('input[type="text"]').focus(function(){
  8. if(this.value=='Enter Value'){this.value=''}
  9. });
  10.  
  11. $('input[type="text"]').blur(function(){
  12. if(this.value==''){this.value='Enter Value'}
  13. });
  14.  
  15. });

Report this snippet  

You need to login to post a comment.