Click to See Complete Forum and Search --> : Checkbox verify ALL


maggiemay654
05-01-2003, 04:59 PM
Hello!
I have this script that should verify that ALL boxes in the form are checked. It works for all but the last box, you can click the last box only & it will perform the action. Can you tell me how to make it verify the last box as well? Thank you so much!!
Here's the script:
<HTML><HEAD><TITLE> None</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkCheckBox(f){
if (f.charge1.checked == false )
{
alert('Please check all boxes to continue.');
return false;
}else
return true;
}function checkCheckBox(f){
if (f.charge2.checked == false )
{
alert('Please check all boxes to continue.');
return false;
}else
return true;
}
function checkCheckBox(f){
if (f.charge3.checked == false )
{
alert('Please check all boxes to continue.');
return false;
}else
return true;
}
// End -->
</script></HEAD><BODY>

<form name="shipping" ACTION="orderform.htm" METHOD="POST" onsubmit="return checkCheckBox(this)">
<input type="checkbox" name="charge1" value="0"> Description 1 <p>

<input type="checkbox" name="charge2" value="0"> Description 2 <p>

<input type="checkbox" name="charge3" value="0"> Description 3 <p>

<input type=submit value="submit">
</form>

</BODY>
</html>

pyro
05-01-2003, 05:21 PM
Try this one out... It minimizes your code, and works. :D Yours had problems due to the fact that you called the same function. It obviously only ran that last instance of it, checkbox 3.

<script language="javascript" type="text/javascript">
function checkCheckBox(f) {
if (f.charge1.checked == false || f.charge2.checked == false || f.charge3.checked == false) {
alert("Please check all boxes to continue.");
return false;
}
else {
return true;
}
}
</script>

maggiemay654
05-01-2003, 05:26 PM
You're awesome, Pyro - it works perfectly now! I suspected I was 'code heavy' but didn't know another way - THANK YOU SO MUCH!

pyro
05-01-2003, 05:28 PM
Your very welcome!