Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, any one know why this script

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
Hi, any one know why this script doesn't work right??

for(i=0; i<=6; i++) {
if (!document.formsreq.APPLICATIONS(i).checked) {
alert (&quot;Please select form.&quot;);
return false;
}
else {
return true;
}
}

this is supposed to check to see if any one of 7 checkboxes are checked, and if any one is checked it's supposed to submit, but this code for some reason only works if the first checkbox is checked, not if any other checkboxes are checked,why??
 
this might work:

for(i=0; i<=6; i++)
{
if (!document.formsreq.APPLICATIONS(i).checked)
{continue;}
else{return true;}
}
alert(&quot;Please select form.&quot;)
return false; jared@aauser.com
 
Try this...

Code:
<html>
<script language=&quot;javascript&quot;>
function validate(){
	var boolFlag = false
	for (i=0; i<=6; i++) {
  	if (document.formsreq.APPLICATIONS(i).checked) {
  		boolFlag = true
  	}
  }
  if (boolFlag == true) {
  	return true;
	}        
	else {
		alert(&quot;You must select a form!&quot;);
		return false;
	}
}
</script>
<body>
<form id=formsreq name=formsreq>
	0. <input type=checkbox id=APPLICATIONS><br>
	1. <input type=checkbox id=APPLICATIONS><br>
	2. <input type=checkbox id=APPLICATIONS><br>
	3. <input type=checkbox id=APPLICATIONS><br>
	4. <input type=checkbox id=APPLICATIONS><br>
	5. <input type=checkbox id=APPLICATIONS><br>
	6. <input type=checkbox id=APPLICATIONS><br>
	<input type=button onClick=&quot;validate()&quot;>
</form>
</body>
</html>

later, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top