This is a kind of similar duplicate to some others here, but I think I'm using event.preventDefault()
correctly in this case.
Here's a JSFiddle you can see the code with: http://jsfiddle.net/SeEw2/2/
Basically, click the Submit button.
In Chrome: Nothing happens - correct response.
In Firefox: Page reloads, oh noes!
So why is the page reloading in Firefox and not Chrome? I've been Firebugging it and no errors come up in either...
Because your not passing the event object like
function(event)
, but my question is why even go through all this when you can make thetype="button"
and onclick pass the values? In essence that what your doing with this whole process.Ah I've had a similar problem in that past. Rather than event.preventDefault() try passing the event to:
I know it says IE, but I've never had a problem with it since =]
I solved it this way, due my code is a little bit different this may be helpful for other people. My initial code looked like this.
My js function looked like
I had to pass the parameter event in the function call and receive it in the function.
js code:
I hope it helps.
Instead of looking for a click event on the submit button, why not use the $(form).submit handler?
As long as you have 'return false' at the end of the handler, the page won't reload.
The variable
event
in your code is not initialized.http://jsfiddle.net/SeEw2/4/
extract :