I have a form and I want to show an error message if a user has clicked inside the field and then out of it. I have this code and it works perfectly
<form action="sign_in.php" method="post" id="sign_in_form">
<div class="form-group">
<label for="email" style="font-weight: bold; cursor: text;"><span style="color:red;">* </span>Email Address</label>
<input type="text" name="email_3" id="email_3" class="form-control form-control-lg" onblur="check();"
value="" style="width:455px; background-color:#EEEEEE;">
</div>
<div id="errorname"></div>
<script>
function check(){
if(document.getElementById('email_3').value=='' || !document.getElementById('email_3').value.length){
document.getElementById('errorname').innerHTML="this is an invalid name";
}
}
</script>
Now the problem is that if I clicked again inside the field the message is still available. I need to remove the message if clicked inside again until I clicked outside of the field the message comes again. How could I do that?