Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /*
  2. * formAutoFill.js v1.0
  3. * September 2015
  4. *
  5. *
  6. * Author: Alexandr Vred Kovalenko (Alexandr.Vred@gmail.com)
  7. * Author: Nil Borodylyua (brdnlsrg@gmail.com)
  8. *
  9. * Copyright 2015
  10. * License MIT
  11. */
  12.  
  13. function autoForm(args, parent) {
  14. var defaults = {
  15. default: 'asdadsSD',
  16. email: 'test@test.com',
  17. tel: '+380931111111'
  18. };
  19.  
  20. args = $.extend({}, defaults, args);
  21. parent = typeof parent !== 'undefined' ? parent : 'html';
  22.  
  23. var input = $(parent).find('input'),
  24. textarea = $(parent).find('textarea');
  25.  
  26. textarea.val(args.default);
  27. input.each(function () {
  28.  
  29. var $this = $(this),
  30. type = $this.attr('type'),
  31. name = $this.attr('name');
  32.  
  33. if (args[type])
  34. $this.val(args[type]);
  35. else if (args[name])
  36. $this.val(args[name]);
  37. else
  38. $this.val(args.default);
  39. });
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement