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

157
Views
Why would a <button>, with attribute type="submit", not be submitted with the form when using HTMLFormElement.submit()?

I happen to have the following form:

<form method="post" action=<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?> enctype="multipart/form-data">
  <button type="submit" name="identifier" value="wikipedea_form">
    Add Post
  </button>
</form>

I use jquery to submit this form as

$("form").submit();

This doesn't send the post data $_POST["identifier"]. I assume jQuery uses HTMLFormElement.submit() under the hood. The MDN docs say that:

<input> with attribute type="submit" will not be submitted with the form when using HTMLFormElement.submit()...

I think the same applies to the button tag as well. Just to be 100% sure I am asking here. May be it depends on the browser etc etc...

So, Would <button> with attribute type="submit" not be submitted with the form when using HTMLFormElement.submit()? Please quote official documentation to back up your answer.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Only successful controls are submitted in normal form submission.

Submit buttons are only successful if they are used to submit the form (or if the form is submitted via Enter in a single text input in which case the default submit button is successful). This lets you distinguish which button was used to submit the form in cases such as:

<button name="action" value="like">Like</button>
<button name="action" value="dislike">Dislike</button>

Trigging form submission with JS bypasses the selection of a submit button.


  1. For each element field in controls, in tree order:

    1. If any of the following is true:
      • The field element has a datalist element ancestor.
      • The field element is disabled.
      • The field element is a button but it is not submitter.
      • The field element is an input element whose type attribute is in the Checkbox state and whose checkedness is false.
      • The field element is an input element whose type attribute is in the Radio Button state and whose checkedness is false.

    Then continue.

— https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set


If you want to submit data with a form every time it is submitted, regardless of how it was submitted: Use <input type="hidden" ...>

about 4 years ago · Juan Pablo Isaza 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!