Hi, right now I have it that an email is put into the function and it adds a paragraph saying if it is valid or not.
what I need to do is add a text box that someone would type their email into and then the background of the textbox would go transparent if the email is valid and the background would go red if it is not a valid email. I need to do this by using the addEventListener blur event. I’m not sure if I’m close?
<!Doctype html>
<html>
<!--Header-->
<head>
<title>JavaScript</title>
<!--can contain javascript imports but page javascipt should be at the bottom of the body-->
</head>
<!--Body-->
<body>
<!---- Email Html--->
<h4>Email Validation!</h4>
<label for="inputEmail">Enter your email:</label>
<input type="email" id="emailInput" name="email">
<!--javascript code-->
<script type="text/javascript">
function validateEmail(email, emailPattern){
emailPattern = (emailPattern instanceof RegExp) ? emailPattern : /[\w-\.]+@([\w-]+\.)+[\w-]{2,4}/;
var matchResults = emailPattern.test(email);
var message = matchResults ? 'Your Email is Valid' : 'Your Email is Invalid' ;
var emailParagraph = document.createElement("p");
document.body.appendChild(emailParagraph);
emailParagraph.appendChild(document.createTextNode(message));
return matchResults;
}
validateEmail('emailImput');
document.addEventListener("blur", function(validateEmail){ validateEmail.target.style.backgroundColor = "transparent";});
</script>
<!--end of scripts-->
</body>
</html>