Bind Submit form Event handler after previously attached handler


/ Published in: jQuery
Save to your folder(s)

Bind Submit form Event handler after previously attached handler


Copy this code and paste it in your HTML
  1. var form =jQuery('form[name="testform"]');
  2.  
  3. var events = form.data("events");
  4.  
  5. var previous_submit = events.submit[0]['handler'];
  6.  
  7. form.unbind('submit', events.submit[0]);
  8.  
  9.  
  10. form.bind('submit', function() {
  11.  
  12. if (previous_submit.call(this)==false)
  13. return false;
  14.  
  15. var data = {};
  16. jQuery(this).find('input[name],select[name],textarea[name]').each(
  17. function(index, input) {
  18. data[input.name] = input.value;
  19. })
  20.  
  21. $.when(
  22. $.ajax ( {
  23. type : 'POST',
  24. url : location.protocol+'//'+location.hostname+location.pathname,
  25. data: data,
  26. success: onSuccess
  27. })
  28. ).done (function() {
  29. console.log('form submitted');
  30. })
  31.  
  32.  
  33. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.