Close this search box.

Intercept a form submit with jQuery and prevent or allow submission

Goal: Intercept a form submit, find out what submit button was clicked/invoked and decide to prevent the submission or continue to submit.


$(document).ready(function() {
    $("form").submit(function(e) {
        if ( == "myButton") {
            if (some status is true continue to submit the form)
                return true;
                //If the status above is false continue to prompt the user if they want to submit or not
            var ok = confirm('Do you really want to save your data?');
            if (ok) {               
                return true;
            else {
                //Prevent the submit event and remain on the screen
                return false;

This article is part of the GWB Archives. Original Author: Renso Hollhumer

Related Posts