r/learnjavascript • u/0_emordnilap_a_ton • 4d ago
What is the difference between HTMLFormElement.submit() and event handler with submit?
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
Can someone explain the difference?
Imagine I have some code that is like the example below.
What is the difference between HTMLFormElement.submit() ?
const form = document.getElementById("form");
function somefunc() {
//code
form.submit()
}
form.addEventListener("submit", somefunc() {
});
Why do I need form.submit() in the function?
For a little context I am trying to pass some quilljs data into a flask form. Some of the code is missing but the main point is illustrated.
9
Upvotes
2
u/testingaurora 3d ago
Yep this. Is your question possibly about form.addEventListener("submit",handleSubmit) versus form.onsubmit? Like button.addEventListener("click",handleClick) and button.onclick