Javascript

How To Do Things After Form Submit With JQuery

Posted by Weston Ganger on March 27, 2016

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:


Posted in Javascript and Tagged with jquery javascript forms 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts