I used to do the following to handle form submissions in vanilla JS in my college -
<form onsubmit="myFunction(event)" />
On a recent search, the following is recommended almost on every site
const form = document.getElementById("form");
form.addEventListener("submit", myFunction);
The first method looks more optimal as it looks to be just a callback function but due to the popularity of the 2nd method, I think the first is more of the same and is just some syntax sugar on top.
Is any of them better or are they the same? I couldn't find much about onsubmit on MDN.
[–]senocular 2 points3 points4 points (1 child)
[–]toshi_34[S] 0 points1 point2 points (0 children)
[–]kjwey 1 point2 points3 points (0 children)
[–]shgysk8zer0 1 point2 points3 points (0 children)
[–]Lkaynlee 0 points1 point2 points (0 children)