0Pricing
JavaScript Academy · Lesson

The submit Event

Handle form submission and prevent reloads.

Submitting Forms

The submit event fires when a form is sent, whether by clicking a submit button or pressing Enter in a field. It is the right place to handle form data.

Listening on the Form

Attach the listener to the form element itself, not to the submit button, so all submission paths are covered.

const form = document.querySelector("#signup");
form.addEventListener("submit", (e) => {
  console.log("submitting");
});

All lessons in this course

  1. Reading Input Values
  2. The submit Event
  3. Client-Side Validation
  4. The Constraint Validation API
← Back to JavaScript Academy