Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
How to override (disable) the "submit" behaviour of a button tag inside of a form tag?
<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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report

0

This will disable via javascript

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

But you can just define the type

<button type='button'>click</button>
over 4 years ago · Santiago Trujillo Report

0

There are occasions where you want to keep the niceties of a submit button (for instance, on a mobile device, where the submit button can be triggered from the keyboard, but only if the button is part of the form and of type submit). In this case what you need to do is prevent the default action of the button.

Using jQuery 1.7+ (using .on - I highly recommend reading the documentation - there are many nuances to using .on that can vastly affect performance)

$(document).on("click", "button", "event", function(evt) {
    evt.preventDefault();
    ...
}

Using older versions of jQuery...

$("#button-id").bind("click", function(evt, ui) {
    evt.preventDefault();
    ...
}

Note that you can use any selector (select by class, element type etc) or an method of binding to the event (instead of .bind, use .live, .delegate as appropriate to your version of jquery.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!