0

I have an HTML form in which I use the browser's native validation. However, inside my form I have another button unrelated to the submit that does a different action. When I press that button howver, it fires off the browser's validation, how can I disable that

<form>
    <input type="text" required />
    <button>I shouldn't fire validation</button>
    <input type="submit" value="I fire the validation">
</form>
NicolasMoise
  • 7,261
  • 10
  • 44
  • 65

2 Answers2

1

In HTML 5, button has a default behavior as a submit type. So

<button type="button">Button</button>
Arjit
  • 3,290
  • 1
  • 17
  • 18
0

A button by it's own don't fire the submit. You probably have an event setted on it. If you don't, try this other sol

You could use

<form>
    <input type="text" required />
    <button type="button">I shouldn't fire validation</button>
    <input type="submit" value="I fire the validation">
</form>

It seems weird, but I got if from this example (just in the end of 4.9 section): http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#concept-button

And you can see it working: http://jsfiddle.net/xmhpF/

D. Melo
  • 2,139
  • 2
  • 14
  • 19