Posted By

cdurocher on 06/22/11


Tagged

form jquery


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

XtreamIT
niceslice
ryonley


jQuery: Input text default value, clear value on click, if typed value erased, get default value back


 / Published in: jQuery
 

Specifiy a default value to input text field. OnFocus, the default value clear and let you type a new value. If typed value is erased then the default value is set back.

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. swapValue = [];
  4. $("#qvtit-qvtit").each(function(i){
  5. swapValue[i] = $(this).val();
  6. $(this).focus(function(){
  7. if ($(this).val() == swapValue[i]) {
  8. $(this).val("");
  9. }
  10. $(this).addClass("focus");
  11. }).blur(function(){
  12. if ($.trim($(this).val()) == "") {
  13. $(this).val(swapValue[i]);
  14. $(this).removeClass("focus");
  15. }
  16. });
  17. });
  18. });
  19. </script>

Report this snippet  

You need to login to post a comment.