Design comparison
Solution retrospective
I'm having a bit of trouble with the form validation any help would be appreciated
Community feedback
- @noutcheu1Posted about 1 year ago
can you please describe what was your probleme ?
0@jmahamedPosted about 1 year agomy problem was that the form would submit and then show the error messages after a few clicks. For example I leave everything blank and try to submit it would take a few clicks for the errors to show up and the form will have submitted anyway. i want to fix that @noutcheu1
0@noutcheu1Posted about 1 year ago@jmahamed I your probleme is you'are not stop the submit of your form just use this pattern first of all define a ID on a form like this
<form action="#form-card" id="Myform" method="get"> // .... // </form>
and in a js file get this id
let form = document.querySelector("#Myform");
add an new event when you submit form whit addeventlistener methode
form.addEventListener("submit", (event)=>{ event.preventDefault(); // this method stop the the form submit and then you can't do what you want // stop form submission // add your code bellow and if your form it is correct use this methode to send your your if(send_form){ form.submit(); } } });
I hope it will help you .
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord