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");
});