I have a form validation function that loops through the form elements checking for empty fields – code below:
function formValidate(ourform){
var formelems = document.getElementById(ourform).elements;
for (var i=0; i<formelems.length; i++){
if(formelems[i].value == "") {
alert("Empty Field(s). Please fill in all the fields.");
return false;
}
}
}
the problem is that my form does not return false if there’s an empty field – it processes the form. I have solved this before but now i just cannot remember how.
Thanks.
Basically the answer is that in your example, you aren’t actually returning anything. In Pandiya’s example he is returning true/false depending on the conditions. Remember to also use a return statement in whatever even call you are using, probably in your example it would be