On Thu, Oct 29, 2009 at 9:21 AM, SamCKayak <s...@elearningcorner.com> wrote:

> I've added a jQuery .onClick to a form submit.
>
> Is there a way to prevent the form from submitting?
>


return false in the click handler.

$('#myFormSubmit').click(function() {
     do stuff;
     return false;
});

Altho, I'm wondering if it'd be better handled (understanding that "better"
is subjective) to use the form's submit method rather than the submit
button's click method.

e.g.:

$('#myFormID').submit(function() {
     do stuff;
     return false;
}

I can't elaborate on why, other than I've been told way back in the day that
it's "better" to not use an onclick on a submit button, but rather the
onsubmit on the form itself.

Maybe somebody on the list can elaborate on that... but either way should
give you the results that you're looking for.

-- 
Charlie Griefer
http://charlie.griefer.com/

I have failed as much as I have succeeded. But I love my life. I love my
wife. And I wish you my kind of success.

Reply via email to