HTML button to NOT submit form
Posted
by arik-so
on Stack Overflow
See other posts from Stack Overflow
or by arik-so
Published on 2010-05-13T10:01:12Z
Indexed on
2010/05/13
10:04 UTC
Read the original article
Hit count: 402
Hello,
I have a form. Outside that form, I have a button. A simple button, like this:
<button>My Button</button>
Nevertheless, when I click it, it submits the form. Here's the code:
<form id="myform">
<input />
</form>
<button>My Button</button>
All this button should do is some JavaScript. But even when it looks just like in the code above, it submits the form. When I change the tag button to span, it works perfectly. But unfortunately, it needs to be a button. Is there any way to block that button from submitting the form? Like e. g.
<button onclick="document.getElementById('myform').doNotSubmit();">My Button</button>
Thanks in advance!
© Stack Overflow or respective owner