Asked • 05/10/19

HTML button to NOT submit form?

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>

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.