I went in cycles on how to make span element hidden again when JavaScript check is successful. At the present time onchangeand onblurthere is a red band, indicating an error, if there is no text or numbers in the name field. This does not disappear when you enter the correct text. I'm just wondering how to delete this message when the correct text is inserted into it? The code is below.
JavaScript:
function validateName() {
var name = form.firstname.value;
if (form.firstname.value == "") {
document.getElementById("firstnameInvalid").style.visibility = "visible";
return false;
} if (/[0-9]/.test(name)) {
document.getElementById("firstnameInvalid").style.visibility = "visible";
return false;
}
return true;
}
HTML form:
<form name="form" method="post" action= "userdetails.html" onsubmit="return validate(this)">
<p>First Name:<input type="text" name="firstname" onblur="validateName()" onchange="validateName()" id="name">
<span id="firstnameInvalid" style="color:red; visibility:hidden"> First Name is Invalid </span>
</p>
source
share