I know this question sounds a lot like a bunch of others that are out there, but I swear I can't find the right solution anywhere. I have a legacy form that has multiple submit buttons. If one is clicked, I need to do a bit of client-side validation and potentially stop the submit. If the other is clicked, I don't need to do this validation.
What I'm finding is that if I create a .submit()
handler, I can't seem to access which button was actually clicked. On the other hand, if I capture the .click()
event of the button I need to worry about, then I can't prevent the form from submitting via .preventDefault()
(or .stopImmediatePropagation()
).
Here's the most recent iteration of the code that attempts to use the buttons .click()
handler:
$('#nextButton').click( function( e ) {
e.preventDefault(); // The form submits anyway (which kind of makes sense)
// return false also doesn't prevent the submission
// If any session question is unanswered, abort
/* $('#registrants input:text[id$="Answer"]').each( function( i, input ) {
if( $.trim( $(input).val() ) == '' ) {
submit = false;
}
});*/
});
What am I missing here? There has to be a way to do this and it seems like it should be fairly simple, but I'll be damned if I've had any luck at all.
Thanks.