Advertisement

02.13.2008 at 07:16AM PST, ID: 23159767
[x]
Attachment Details

Validating checkboxes using javascript - page still submits even though no checkboxes are checked

Asked by ev72178 in JavaScript

Tags: Javascript, ColdFusion

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["submitChecks"]["arrayValue"].length;i++){
if(document.forms["submitChecks"]["arrayValue"][i].checked){
isChecked=true
}
}
if(isChecked){
document.forms["submitChecks"].submit()
}
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="GetUnacceptedRecords">
<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
 
Loading Advertisement...
 
[+][-]02.13.2008 at 07:26AM PST, ID: 20884927

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.13.2008 at 07:35AM PST, ID: 20885015

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.13.2008 at 07:49AM PST, ID: 20885170

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.13.2008 at 07:55AM PST, ID: 20885212

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: Javascript, ColdFusion
Sign Up Now!
Solution Provided By: third
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.13.2008 at 08:02AM PST, ID: 20885279

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628