Vanilla JavaScript Stop Form Submit
Let's say we want to add form validation in JavaScript, first we need to stop the form from actually submitting.
We can do this very simply in JavaScript.
HTML Structure
<form onsubmit="return validate();" novalidate>
<input type="text" name="name"...
h.daily-dev-tips.com2 min read
Francisco Quintero
Software Engineer & Ruby on Rails Developer
event.preventDefault()should be use when the submit event is going to be handled somewhere else.You're example is simple but works as expected 😁