Ben Holness
Ben Holness

Reputation: 2707

How can I prevent javascript from submitting a form on a script error?

I am trying to debug a javascript problem, but the problem happens when submitting a form. I see a javascript error briefly in the console window, then the form gets submitted.

Is there a way to make the default not to submit the form, so I can see the script error before I get sent to the form submit page?

The code is using jquery with a

$('#form').on('submit', function() {
    // validation code with script error somewhere
});

Upvotes: 0

Views: 80

Answers (1)

rink.attendant.6
rink.attendant.6

Reputation: 46218

$('#form').on('submit', function(e) {
    e.preventDefault();
    // validation code with script error somewhere
});

Upvotes: 3

Related Questions