Preventing Form Submit with button element in Firefox
by
on March 11th, 2009 at 10:17 AM (2541 Views)
I had an issue in Firefox where I wanted a <button> element to fire a Javascript function onclick.
However, I found in Firefox that the button also performed a submit on the form, which I didn't want.
After a little investigation I discovered that the default type for a button element is submit. Apparently a bug in IE prevents it from firing.
So, how to fix?
Add a type="button" property to your <button> element
I would also include return false as the last line of your JS function, just to be on the safe side.Code:<button id="button1" type="button" onclick="JS_Function()">Click</button>








Email Blog Entry