Javascript not working

I want the "valid_email" to appear only when the user types in the correct email https://codepen.io/saad-shehzad-the-bashful/pen/JoPwQgN
4 Replies
Chris Bolson
Chris Bolson4w ago
Change this line:
theMessage.addEventListener('input', thisFunction());
theMessage.addEventListener('input', thisFunction());
To this:
theMessage.addEventListener('input', thisFunction);
theMessage.addEventListener('input', thisFunction);
By including the brackets you are actually calling the function on load. By removing the brackets you are only passing a reference to it so it will only be called when the input actually gets the event. I am sure that somebody else might be able to explain this in more detail.
13eck
13eck4w ago
That's a pretty accurate description, I'd just clarify that when you call a function (thisFunction() ) the return value of said function is put in its place. Since thisFunction has no return value, you're passing in undefined (the default return value if no value is returned) to the function handler Also, I hope you're not using this in production, @Code-S ♛, because that is not a great email validator
13eck
13eck4w ago
:p
Code-S ♛
Code-S ♛OP4w ago
oooooh it was that simple tysm chris and just

Did you find this page helpful?