Do Things After Form Submit With JQuery

Posted By Weston Ganger

I wanted an easy to manipulate the DOM after form has been submitted via javascript for example adding a fake loading bar.

You can do this using jQuery submit.

$('#my-form').submit(function(e){
  e.preventDefault(); // dont submit multiple times
  this.submit(); // use native js submit

  setTimeout(function(){
    $('#my-input').val('');
  });
});

Note: If you do not cancel the event and then use js submit then the actions will be performed before the forms submission.
Note 2: If you do not use setTimeout() it will do the work before submission in Chrome which you do not want.

Related External Links:

Article Topic:Software Development - Javascript

Date:March 27, 2016