84
rated 0 times
[
85]
[
1]
/ answers: 1 / hits: 50009
/ 10 Years ago, tue, april 15, 2014, 12:00:00
I am stuck on how to make a span element become hidden again when the JavaScript validation succeeds. Currently onchange
and onblur
a red span appears showing an error if there is no text or if there are numbers in a name field. This does not disappear when the correct text is put in. I was just wondering how to make this message disappear when the correct text is put in? 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;
}
Form HTML:
<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>
More From » html