Advertisement
Guest User

Untitled

a guest
May 29th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // reseting a form set it back to his original value.
  2. (function ($) {
  3. $.fn.reset = function () {
  4. $(this).each(function () {
  5. this.reset();
  6. });
  7.  
  8. return this;
  9. };
  10. }(jQuery));
  11.  
  12. // cleaning a form set it to an empty string or false. You can also set a default value.
  13. (function ($) {
  14. $.fn.clean = function (default_value) {
  15. default_value = default_value || false;
  16.  
  17. $(this).filter('select').find('option').removeAttr('selected');
  18. $(this).filter(':checkbox').attr('checked', false);
  19.  
  20. if (default_value) {
  21. $(this).filter(':input:not(:checkbox)').each(function () {
  22. $(this).val(this.defaultValue);
  23. });
  24. } else {
  25. $(this).filter(':input:not(:submit, :button, :reset, :checkbox, :radio)').val('');
  26. }
  27. return this;
  28. };
  29. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement