Design comparison
Solution retrospective
I could not add the JavaScript code for this website. It will be much appreciated if you can help me with this.
Community feedback
- @Wesleys-hubPosted almost 4 years ago
Hey man, i would sugget adding an id to the form and the input. Make the styles following the design (active-states) image and add them when the user fills in either a correct or a wrong input
// get the form and input const form = document.getElementById("form"); const email = document.getElementById("email");
// add event listener to button form.addEventListener("submit", (e) => { e.preventDefault(); // get the value of the input const emailVal = email.value;
let validateEmail = () => { let filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; // if not correct add error class and remove correct class if (!filter.test(emailVal)) { form.classList.add("form-error"); form.classList.remove("form-correct"); // if correct add correct class and remove error class } else { form.classList.remove("form-error"); form.classList.add("form-correct"); } }; validateEmail(); });
2 - @just-a-devguyPosted almost 4 years ago
What you mean by not being able to add the js. Is it that you're not understanding what's required or is it that you understand what's expected but not how to do it?
2@ShahinthecoderPosted almost 4 years ago@adluders I do not know how to do it. Checked StackOverflow but could not get a grasp on it.
1@just-a-devguyPosted almost 4 years ago@Shahinthecoder sorry for the delayed response, it seems that the comment below should suffice.
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