0

New to javascript but I have a good analytical mind....that being said, I have the following code in onSubmit() validation:

else if (cofaCOURRIEL == null || cofaCOURRIEL == "") {
		alert('Le champ COURRIEL doit être rempli.');
		document.forms["COFA_AIG"] ["COURRIEL"].focus();
		return false;
	}
	
	else if (cofaCOURRIEL) {
		if ( (atPOS < 1) || (dotPOS < atPOS + 2) || ((dotpos + 2) >= cofaCOURRIEL.length) ) {
			alert('Adresse de courriel invalide.');
			document.forms["COFA_AIG"] ["COURRIEL"].focus();
			return false;
		}
	}
	
	else if (cofaDATE == null || cofaDATE == "") {
		alert('Le champ DATE doit être rempli.');
		document.forms["COFA_AIG"] ["DATE"].focus();
		return false;
	}

I understand it is not the best way to validate client side, but I will be doing php server side validation as well.

My problem is that once the variable "cofaCOURRIEL" is valid, the script stops and returns true....not sure why...I'm guessing I'm missing an "else" statement after the embedded "if" statement, but I'm only guessing and if I'm correct, I wouldn't know what to put in the else statement to let it not break out of the validation...

any input?

Thanks!

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Shanti C
0

if you use else if conditional statement, then your control goes for one valid condition.
If you want to go for every condition to be checked , then simply use if condition for every input.
and also check it:

if (cofaCOURRIEL == null || cofaCOURRIEL == "") {
		alert('Le champ COURRIEL doit être rempli.');
		document.forms["COFA_AIG"] ["COURRIEL"].focus();
		return false;
	}
	
	else {
		if ( (atPOS < 1) || (dotPOS < atPOS + 2) || ((dotpos + 2) >= cofaCOURRIEL.length) ) {
			alert('Adresse de courriel invalide.');
			document.forms["COFA_AIG"] ["COURRIEL"].focus();
			return false;
		}
	}
	
	 if (cofaDATE == null || cofaDATE == "") {
		alert('Le champ DATE doit être rempli.');
		document.forms["COFA_AIG"] ["DATE"].focus();
		return false;
	}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.