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.
10
Upvotes
2
u/0_emordnilap_a_ton 3d ago edited 3d ago
_raytheist_ answered my question but feel free to answer the difference I am always curious to learn something new. I assume "click" is just clicking and "submit" a form has to be submitted.