🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

Submit

AI & DATA SCIENCE // submit

A submit control (<button type="submit"> or <input type="submit">) triggers the enclosing form to validate and send its data.

Syntax

<button type="submit">Place Order</button>
<!-- or -->
<input type="submit" value="Place Order">

Deep Dive Course

A submit control, when clicked, first triggers the browser's built-in form validation (checking `required` fields, `type="email"` formatting, `min`/`max` ranges, etc.) — if anything fails, the browser shows its native validation message and blocks submission. If validation passes, the form's data is sent according to its `action`/`method`, or, if a JavaScript `submit` event listener calls `event.preventDefault()`, the default navigation is cancelled so the code can handle the data itself (e.g. via `fetch`).

1Understanding Submit

A submit control, when clicked, first triggers the browser's built-in form validation (checking required fields, type="email" formatting, min/max ranges, etc.) — if anything fails, the browser shows its native validation message and blocks submission. If validation passes, the form's data is sent according to its action/method, or, if a JavaScript submit event listener calls event.preventDefault(), the default navigation is cancelled so the code can handle the data itself (e.g. via fetch).

💡

A form can have multiple submit buttons with different name/value pairs — whichever one the user actually clicks has its own value included in the submitted data, letting the server distinguish which button was pressed (e.g. 'Save Draft' vs 'Publish').

editor.html
<form>
  <input type="email" name="email" required>
  <button type="submit">Sign Up</button>
</form>
localhost:3000

2Practical Example

Here is a real-world application of Submit showing how it is used in production HTML.

editor.html
<!-- Two differently-named submit buttons in one form -->
<button type="submit" name="action" value="save_draft">Save Draft</button>
<button type="submit" name="action" value="publish">Publish</button>
localhost:3000

3Best Practices

Follow these guidelines when working with Submit:

1. Use a clear, action-oriented label ('Create Account', not just 'Submit')

2. Rely on native HTML validation (required, type, pattern) before adding custom JavaScript validation

3. Disable the submit button (or show a loading state) while an async submission is in progress, to prevent duplicate submits

⚠️

Tip: A form can have multiple submit buttons with different name/value pairs — whichever one the user actually clicks has its own value included in the submitted data, letting the server distinguish which button was pressed (e.g. 'Save Draft' vs 'Publish').

editor.html
<form>
  <input type="email" name="email" required>
  <button type="submit">Sign Up</button>
</form>
localhost:3000

Examples

Example 01Basic Usage
<form>
  <input type="email" name="email" required>
  <button type="submit">Sign Up</button>
</form>
Example 02Advanced Example
<!-- Two differently-named submit buttons in one form -->
<button type="submit" name="action" value="save_draft">Save Draft</button>
<button type="submit" name="action" value="publish">Publish</button>

Best Practices

  • Use a clear, action-oriented label ('Create Account', not just 'Submit')
  • Rely on native HTML validation (required, type, pattern) before adding custom JavaScript validation
  • Disable the submit button (or show a loading state) while an async submission is in progress, to prevent duplicate submits

Interview Question

What happens by default when a submit button is clicked inside a form with invalid required fields?

Hint: Think about the browser's built-in validation, before any custom JavaScript runs.

The browser runs its built-in constraint validation first — checking required fields are filled, and that values match their type/pattern/min/max constraints. If anything fails, the browser blocks the submission entirely and displays its own native error message near the offending field (e.g. 'Please fill out this field'), and no network request or JavaScript submit handler runs at all until the user fixes it.

Exercises

EasyPractice using Submit in a real scenario.
View Solution
<form>
  <input type="email" name="email" required>
  <button type="submit">Sign Up</button>
</form>

Frequently Asked Questions

What happens by default when a submit button is clicked inside a form with invalid required fields?

The browser runs its built-in constraint validation first — checking required fields are filled, and that values match their type/pattern/min/max constraints. If anything fails, the browser blocks the submission entirely and displays its own native error message near the offending field (e.g. 'Please fill out this field'), and no network request or JavaScript submit handler runs at all until the user fixes it.

Related Functions

button-tagform-tagReset