troubleshooting Question

not able to loop over checboxes

Avatar of -Dman100-
-Dman100-Flag for United States of America asked on
JavaScript
3 Comments2 Solutions277 ViewsLast Modified:
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;
		}
	}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros