Hello.
I have a .cfm page that has a form (submitChecks) and a checkbox (arrayValue). Upon submitting this form, I need to make sure that at leaast one checkbox has been selected. If no checkboxes have been selected, an alert box pops up. This all works fine until the user clicks OK on the alert box. The form still submits. I do not want the form to submit. Here is my code:
<script language="JavaScript">
function chkChecks(){
isChecked=false
for(var i=0;i<document.forms["subm
itChecks"]
["arrayVal
ue"].lengt
h;i++){
if(document.forms["submitC
hecks"]["a
rrayValue"
][i].check
ed){
isChecked=true
}
}
if(isChecked){
document.forms["submitChec
ks"].submi
t()
}
else{
alert('You must select at least one checkbox to resubmit.');
isChecked=false
}
}
</script>
<CFFORM action="testArray.cfm" method="POST" name="submitChecks">
<cfparam name = "form.arrayValue" Default="">
<cfloop query="GetUnacceptedRecord
s">
<td><div align="center" class="style6"><cfinput type="Checkbox" name="arrayValue" value="#TransactionID#"></
div></td>
<input type="Submit" name="Submit" value="Resubmit" onClick="chkChecks()">
Thanks.
Start Free Trial