Buttons inside forms are default type submit
Alec Jacobson
July 18, 2013
I was frustrated that my undo button was submitting my form. My HTML code looked something like:
<form action="." method="GET">
...
<button onclick="undo();">Undo</button>
<button onclick="redo();">Redo</button>
...
</form>
At first I thought it was a javascript problem and some how my undo()
function was submitting the form erroneously. But lo and behold this is the default behavior of a button inside of a form.
So, I needed to change my HTML to:
<form action="." method="GET">
...
<button type=button onclick="undo();">Undo</button>
<button type=button onclick="redo();">Redo</button>
...
</form>