Javascript IE8: All buttons within form trigger submission
I'm facing a problem which I yet haven't found a solution for.
I have a form with two types of buttons inside: one <button type="submit">
, and one plain <button>
. I have a submit event on the form, which should only be triggered by the submit button. Then I have another event bound to the plain button, which actually has nothing to do with the submission of the form; It's a delete button. Even though I return false and prevent the default behavior of that button it still triggers the form submission.
The same problem occurs with all non-submit buttons wi开发者_开发知识库thin forms. If I remove the submit event on the form it works great. It seems to override all other events bound to the buttons inside.
Is there anyway of fixing this?
Trying setting type="button" on the buttons you don't want to submit the form. By default I believe IE8 will try and submit the form for all buttons, not just those where type="submit".
Also how are you overriding the default button behaviour?
It should be in the onclick event ie onclick="return doSomething();"
精彩评论