[英]Javascript simple Form Validation not working
I have been trying to figure this simple code out.我一直在试图弄清楚这个简单的代码。 I have it down to where the IF Firstname is empty or == 1, it will ALERT, but the final IF statement is always ringing true and doesn't alert false or true.
我把它归结为 IF Firstname 为空或 == 1 的地方,它会发出警报,但最终的 IF 语句总是响起,并且不会发出 false 或 true 警报。 Any ideas?
有任何想法吗?
function validateForm()
{
var firstname=document.getElementById('firstname').value.trim();
var count=0;
if (firstname.length==0)
{ alert("EMPTY");
document.getElementById("err_firstname").innerHTML="<br><span class='errorbar'>*This is a required field</span>";
} else {
count++;
alert("COUNTED");
document.getElementById("err_firstname").innerHTML="";
}
if (count==1)
{
return true;
alert("true");
} else {
document.getElementById("err_allerrors").innerHTML="<br><span class='errorbar'>*There is required information missing. Please enter all required data.</span>";
return false;
alert("false");
}
//Verified
}
在alert()
之前返回是问题所在
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.