Reputation: 39
I working on a form but I have some troubles with the last if statement ( it's not working.
count
is global and start as 0
, for each field with the correct character filled in this will happen: count = count+1;
but if I clicked submit and leave 2 fields with not the correct character
( that should be count = 6
) it doesn't give me an alert but skips it
this is how it should be.
function validateForm() {
var fields = ["voornaam", "achternaam", "Email", "Wachtwoord", "Herhaal_Wachtwoord", "Straatnaam", "Huisnummer", "Postcode", "Woonplaats", "Telefoonummer"];
if (pass1.value !== pass2.value) {
alert("Wachtwoord komen niet overeen");
return false;
}
var l = fields.length;
var fieldname;
for (i = 0; i < l; i++) {
fieldname = fields[i];
if (document.forms["register"][fieldname].value === "") {
alert(fieldname + " can not be empty");
return false;
}
}
if (count < 8) {
alert("iets is niet goed ingevuld");
return false;
}
}
Upvotes: 0
Views: 93
Reputation: 375
You have returned the false
boolean before you have given the alert prompt! Just change the last if
statement like this:
if (count < 8) {
alert("iets is niet goed ingevuld");
return false;
}
Upvotes: 1