Design comparison
Solution retrospective
My email verification js code is not working properly.
I have a class
EmailVerification and an instance of it emailInput
.
My verify
method throws an error: Uncaught TypeError: Cannot read properties of undefined (reading 'classList') at HTMLInputElement.verify.
Thank you for taking the time to help me out :)
Community feedback
- @dtomicicPosted over 2 years ago
I've done it by simply making a function which takes email as a parameter and called it in on click of a button to check if the entered email is correctly written if not it displays an error message.
I've checked your code it looks a bit complicated to be honest, you can just make it a function, make a variable with email regex and check in the function if the entered email matches the format and if not display the error message.
It might be a little outdated solution but it'll get you started and you can work on it from there.
0@alisbaiPosted over 2 years ago@dtomicic thank u for the idea, I will create a second is file for email validation with this method. I appreciate your feedback
0 - @vandermsPosted over 2 years ago
Well done!
About your undefined problem, in JavaScript is not always very clear what is
this
when you are using a method. In your case, thethis
inthis.iconError
is the input element, which is the target of the event listener.Try changing this line:
this.DOMInput.addEventListener(eventType, this.verify);
for:
this.DOMInput.addEventListener(eventType, () => this.verify());
0@alisbaiPosted over 2 years ago@vanderms Thank you so much this is so helpful. I was struggling with this the whole morning. I appreciate the help :)
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