Sunday, 29 September 2013

Why does my form validation not work?

Why does my form validation not work?

I have a long form with lot of inputs. I want to validate them at once. So
i used the array elements[] in a for bucle:
var elem = document.frmSearch.elements.getElementsByTagName('input');
var errors = 0;
for(i=0; i<elem.length; i++)
{
if(elements[i].value=="" || elements.value==" ")
{
++errors;
}
else
{
return true;
}
}
if(errors>=1)
{
alert('Fill all gaps!');
}
else
{
return true;
//....
}
}
//Note: errors var count non filled gaps

No comments:

Post a Comment