Reputation: 1344
I have simple form. I want to use jquery to prevent form submit.
$(document).ready(function() {
$('#searchform').submit(function(e) {
alert('Handler for .submit() called.');
event.preventDefault();
return false;
});
});
This works fine in chrome. It just shows me a alert box and does not redirect. But does not work on Firefox or IE9, it shows the alert and then goes ahead with form submission.
I appreciate any help.
Upvotes: 0
Views: 73
Reputation: 359816
Since you're already returning false
, you don't also need any sort of event.preventDefault()
call at all.
The reason that neither of these seem to work for you is that event
is undefined, so an exception is thrown when calling event.preventDefault()
, so the method handler exits prematurely.
Upvotes: 1
Reputation: 4449
event.preventDefault();
should be
e.preventDefault();
Try that and see if it fixes the problem.
Upvotes: 0