Link to home
Start Free TrialLog in
Avatar of -Dman100-
-Dman100-Flag for United States of America

asked on

not able to loop over checboxes

I am trying to loop over a number of checkboxes in an array, but for some reason, I'm not entering the loop?

See my code below.
function validate(){
		var flag = true;
		var container = document.getElementById("inputContainer");
		var ckbxContainer = document.getElementById("checkboxContainer");
		var firstnameErrMsg = document.getElementById('fnameErrMsg');
		var lastnameErrMsg = document.getElementById('lnameErrMsg');
		var emailErrMsg = document.getElementById('emailErrMsg');
		var inputs = container.getElementsByTagName("input");
		var checkboxes = ckbxContainer.getElementsByTagName("checkbox");
		
		for (var i = 0; i < checkboxes.length; i++){
			alert("We are here");
			alert(checkboxes[i].value);
		}
		
		for(var i = 0; i < inputs.length; i++){
			var str = inputs[i].name;
			if (str.indexOf('fname') != -1) {
				if (inputs[i].value == "") {
					firstnameErrMsg.style.display='block';
            		flag = false;
				}	
				else {
					firstnameErrMsg.style.display='none';
				}		
			}
			if (str.indexOf('lname') != -1) {
				if (inputs[i].value == "") {
					lastnameErrMsg.style.display='block';
            		flag = false;
				}	
				else {
					lastnameErrMsg.style.display='none';
				}		
			}
			if (str.indexOf('email') != -1) {
				if (inputs[i].value == "") {
					emailErrMsg.style.display='block';
            		flag = false;
				}
             	else {
                	emailErrMsg.style.display='none';
             	}			
			}
		}	
		if(flag == false){
			return flag;
		}else{
			return flag;
		}
	}

Open in new window

SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks I think you fix my mistake line two :

if( inputs[i].type == "checkbox") {

Open in new window