Design comparison
Solution retrospective
Hi ! This is my first challenge with JS. I just have an issue. When I submit the form with empty fields, the error messages are displayed but when I try to submit the form again, with filled fields, the error messages remain displayed. Do you know how I can fix this ? Thank you :)
Community feedback
- @peterbujakyPosted almost 2 years ago
Hi soles!
Try this:
In your function "ValidateEmail(input, el)",
instead of:
if (input.value.match(validRegex)) { return true;}
use:
if (input.value.match(validRegex)) { input.value =""; el.textContent=""}
<------ This clears the input field and the error message.and in your other function do the same with an else statement at the end:
function isEmpty(inputElement, element, message, label) { if(!inputElement.value) { inputElement.style.borderColor = 'hsl(0, 100%, 74%)'; element.textContent =
${message} cannot be empty
styling(label) }else { inputElement.value = ""; element.textContent = ""; }
}Following the same logic you can reinstate the default styles and remove the red border.
I hope this helps! Great job with the functions by the way!
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