Design comparison
Solution retrospective
How do you set input validation to display border and a warning text?
Feedback is welcome!
Community feedback
- @molszewski34Posted about 3 years ago
I hope this aproach will give you some insight. There are better ways to make it but it is one of simpler to understand.
form.addEventListener("input", () => { if (numPeople.value <= 0) { document.querySelector(".people__error").style.display = "block" numPeople.style.borderColor = "red" } else if (bill.value <= 0) { document.querySelector(".error").style.display = "block" bill.style.borderColor = "red" } else { document.querySelector(".error").style.display = "none" numPeople.style.borderColor = "green" document.querySelector(".people__error").style.display = "none" bill.style.borderColor = "green" } })
Marked as helpful0
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