Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override (disable) the "submit" behaviour of a button tag inside of a form tag?

Tags:

<form action="">   <button>click</button> </form> 

The default behaviour of a button inside a form is to submit that form.

How can I disable the submit behaviour of that button?

like image 990
zwolin Avatar asked Feb 24 '11 05:02

zwolin


People also ask

How do you disable submit button until form is filled?

Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.

How do I stop submit button from submitting?

The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML <form> element.

Does submit button have to be inside form?

Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML.


2 Answers

Add a type="button" to it:

<button type="button">Click</button> 

The types availabe are:

  • "submit": Default value. Submits the form.
  • "reset": Resets the form's inputs.
  • "button": Does nothing.

A good reference: https://developer.mozilla.org/en/DOM/HTMLButtonElement

like image 50
David Tang Avatar answered Sep 23 '22 07:09

David Tang


This will disable via javascript

<button onclick='return false'>click</button> 

But you can just define the type

<button type='button'>click</button> 
like image 44
JohnP Avatar answered Sep 20 '22 07:09

JohnP