Prevent form from submitting via event.preventDefault(); not working

BrownChiLD picture BrownChiLD · Feb 24, 2013 · Viewed 42.9k times · Source

I'm using jQuery to submit my form variables, and im trying to prevent the form from submitting via the usual ways (click submit button or press enter on one of the fields)

i have this:

$('#form').submit(function(){
    event.preventDefault();
});

but it doesn't seem to work my form is still submitting, going to the process.php page..

Answer

steveukx picture steveukx · Feb 24, 2013

If the only thing you need to do is to prevent the default action, you can supply false instead of a function:

$('#form').submit(false);