Click to See Complete Forum and Search --> : Checkbox Validtion Issue


Force
10-08-2003, 11:00 AM
I'm using the following code to validate three checkboxes to ensure that they are checked. The message pops up fine if any are not checked. However, it then submits the form anyway. I'm not seeing what I've done wrong. Thanks for the help. I really appreciate it.

<script language="JavaScript">
function doublecheck(theForm) {
if (
theForm.pledge.checked == false ||
theForm.contact.checked == false ||
theForm.spread.checked == false
)
{
alert ('All 3 boxes must be checked. Thank you.');
return false;
} else {
return true;
}
}
</script>

This is how I'm calling it.

<form action="regcflact.cfm" name="myForm" onsubmit="doublecheck(this);" method="post">

MonkeyBoy
10-08-2003, 11:06 AM
I had a problem like that.

Don't use a submit button. Just a normal one that onClick calls a function like this

if (all three boxes checked){
document.myForm.submit();
} else {
show alert
}

Vladdy
10-08-2003, 11:07 AM
... onsubmit="return doublecheck(this)" ...

Vladdy
10-08-2003, 11:08 AM
Originally posted by MonkeyBoy
I had a problem like that.

Don't use a submit button. Just a normal one that onClick calls a function like this

if (all three boxes checked){
document.myForm.submit();
} else {
show alert
}
and that was a bad solution since it opens a number of ways to bypass the script: for example hitting Enter key ...

MonkeyBoy
10-09-2003, 07:47 AM
If there is no submit button and no onSubmit call then it works fine. Pressing enter would do nothing

pyro
10-09-2003, 07:49 AM
What happenes when users have JavaScript disabled?