3 Replies Latest reply on Jan 21, 2015 12:49 AM by try67

# Calculation based on checkbox response.

Hi there,

I am hoping to get some help with a calculation problem.

I have an Acrobat XI form that needs to total a fee if the corresponding checkbox is ticked.

The checkboxes are named “U1”, “U2” up to “U25”

The text fields are named “CourseFee_U1”, “CourseFee_U2” up to “CourseFee_U25”

The total text field is named “TotalCourseFee”

If “U1” is ticked then “CourseFee_U1” is added to “TotalCourseFee”

This will need to loop as it is possible to have all 25 checkboxes selected.

In addition, I need to have reduced fee apply if a concession checkbox is ticked.

If “ConcessionApplies” is ticked then the corresponding fee text field (“ConcFees_U1”) is added to “TotalCourseFee” instead of corresponding course fee (“CourseFee_U1”).

My knowledge of JavaScript is very little, and I would really appreciate the help.

• ###### 1. Re: Calculation based on checkbox response.

If I understood you correctly, this code should do the trick:

```var maxFields = 25;
var total = 0;
for (var i=1; i<=maxFields; i++) {
if (this.getField("U"+i).value!="Off") {
if (this.getField("ConcessionApplies").value!="Off") {
total+=Number(this.getField("ConcFees_U"+i).valueAsString);
} else total+=Number(this.getField("CourseFee_U"+i).valueAsString);
}
}
event.value = total;
```
• ###### 2. Re: Calculation based on checkbox response.

Thank you so much for your help.

This is calculating the totals if a tick in the “ConcessionApplies” Checkbox however when it is not checked it is not calculating the total of "CourseFee_U.

I only have one “ConcessionApplies” Checkbox, because if the client is eligible for a concession it applies to all of their fees if not the fees are the full price.

Again, I can’t tell you how much I appreciate your help.

• ###### 3. Re: Calculation based on checkbox response.

It should calculate even if the ConcessionApplies box is not ticked, assuming that the "UX" boxes are ticked, of course.

Are there any error messages in the JS console?