Posted By

mscribellito on 03/22/11


Tagged


Versions (?)

Default Value


 / Published in: JavaScript
 

  1. (function($){
  2. $.fn.defaultValue = function() {
  3. var args = arguments;
  4. var c = 0;
  5. return this.each(function() {
  6. var el = $(this);
  7. var def = args[c++];
  8. el.val(def).focus(function() {
  9. if (el.val() == def) {
  10. el.val("");
  11. }
  12. }).blur(function() {
  13. if (el.val().replace(/\s+/, "") == "") {
  14. el.val(def);
  15. }
  16. });
  17. });
  18. };
  19. })(jQuery);
  20.  
  21. $(document).ready(function() {
  22. $('#name').defaultValue("asdf");
  23. });

Report this snippet  

You need to login to post a comment.