How to preventDefault on a .click that submits a form?

I am selecting a form’s submit button ()

For various reasons I cannot use .submit here, where e.preventDefault() works nicely. I must use .click.

(The reason being that I am following the most upvoted answer here: http://stackoverflow.com/questions/4007942/jquery-serializearray-doesnt-include-the-submit-button-that-was-clicked , to try to include the submit button’s value on a .serialized form. jquery’s .serialize and .serializeArray do not include the submit button in their values.)

This does not work:
$(“#myFormsSubmit”).click(e) {
e.preventDefault()
});

The form is still submitted.

What can I do to prevent the form from being submitted here?

Just return false:

$('#submit_button').on('click', function(){
    return false;
});

That seems to do the trick, thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.