I believe you are looking for the focus event.
<div>
<label for="txtEmail">Email:</label>
<input type="text" name="email" id="txtEmail" onblur="validateForm()" onkeypress="clearErrMsg()">
<label id="lblError" style="color:red"></label>
</div>
function validateForm() {
var x = document.getElementById("txtEmail").value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
document.getElementById("lblError").innerHTML = "Enter valid email Address";
} else {
document.getElementById("lblError").innerHTML = "";
}
}
function clearErrMsg() {
document.getElementById("lblError").innerHTML = "";
}
Can i make my validate error be hidden while someone is typing in the field? (not focusing, only while typing more letters onto the input).
i currently have this code:
<div>
Email:
<input type="text" name="email" id="txtEmail" onblur="validateForm()">
<label id="lblError" style="color:red"></label>
</div>
and this javascript:
function validateForm() {
var x = document.getElementById("txtEmail").value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
document.getElementById("lblError").innerHTML = "Enter valid email Address";
}
else {
document.getElementById("lblError").innerHTML = "";
}
}
What this does is validate my e-mail input when input field loses focus.
However i would love for it to hide error when someone focuses again and write more letters.
Exactly like this site: https://www.cosstores.com/en_dkk/login
Is this possible with jquery or javacript?
This removes error message when focusing, which is great, however i want it to be removed when someone types more letter onto the input.