Reputation: 156
For some reason my JavaScript won't validate my forms and I cannot work out why. I've followed examples from many sites like Tizag & W3C, but to no avail.
HTML form:
<form class='login' name='login' onsubmit='return loginValidation();' method='post' action='index.php'>
<p>
<input class='login' type='text' name='nameentry'/><br/>
<input class='login' type='submit' value='Login'/>
</p>
</form>
JavaScript function:
function loginValidation(){
var x=document.form.login.nameentry.value;
if(x==null || x==""){
alert("Enter a name");
return false;
}
}
My code can be seen in action here [an assignment]. Any ideas?
Upvotes: 0
Views: 337
Reputation: 7134
You have an unclosed function (or for block) which is killing the engine:
function testAllQuantity(){
for(i=0;i<150,i++){
quantityValidation(document.getElementById(i));
}
And the for statement is misformed, ,
-> ;
for(i=0;i<150;i++){
Upvotes: 2
Reputation: 716
Second line in function should be
var x=document.forms.login.nameentry.value;
Upvotes: 2