Skip to main content
sw777
Known Participant
Feb 19, 2017 5:21 AM UTC
Answered

Sum numeric fields based on selected checkboxes

I have an Adobe Acrobat form with seven (7) text boxes that contain numeric fields formatted as currency. These are the fees for each subject in a course.

Beside each fee there are two checkboxes that operate exclusively (like radio buttons). The Export Values for each of the two checkboxes are Enrol and RPL.

Here's a screenshot of part of the form...

The textbox field names are as follows...

E101-fee

E102-fee

E104-fee

E105-fee

E107-fee

F102-fee

F104-fee

At the bottom of the form is another currency text field named CourseFee (highlighted blue).

I need the course fee to sum the fees in the other seven text fields, but I only want to include those with the associated "Enrol" checkbox selected. If "RPL" is selected there will be no charge for that subject.

The "Enrol" and "RPL" checkboxes are automatically selected in specific configurations when exclusive checkboxes A, B, or C are selected (these are on another part of the form and are working perfectly). Clicking "A" selects all "Enrol" boxes, "B" selects "RPL" for 5 and "Enrol for 2, "C" selects "RPL" for 6 and "Enrol" for 1.

After this pre-selection occurs and the CourseTotal is displayed, any of the "Enrol" or "RPL" checkboxes can be subsequently changed and the CourseTotal is to update immediately.

Any help would be greatly appreciated.

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Feb 19, 2017 9:49 AM UTC

You can use this code as the custom calculation script of your CourseFee field:

var fields = ["E101", "E102", "E104", "E105", "E107", "F102", "F104"];

var total = 0;

for (var i in fields) {

    if (this.getField(fields).value=="Enrol") {

        total+=Number(this.getField(fields+"-fee").value);

    }

}

event.value = total;

24 replies

K-KAB
Participant
Jun 14, 2021 7:44 PM UTC

@try67Hoping you can help me figure this one out; I thought I had it, but it isn't working--I just continue to get a zero value regardless if the checkmark is "yes" or "no".

If the checkbox (circled in red) is checked, then I want it to add the coresponding value (circled in blue are hidden fields with default values matching the hours listed).

My checkboxes are named Core1, Core2, Core3, etc.; my hidden text fields are listed as CoreHours1, CoreHours2, CoreHours3, etc.

Below is a snip of my file as well as a snip of the code I'm trying to use.

Translate
try67
Community Expert
Community Expert
Jun 14, 2021 8:37 PM UTC

Post the full code as text, or share the file with us, please.

Translate
K-KAB
Participant
Jun 14, 2021 8:40 PM UTC

File attached. Thank you!

Translate
Jun 9, 2020 12:40 AM UTC

@try67.  I am trying to write code for when a checkbox is selected a fee will calculate based on Subtotal and Tax boxes multiplied by .035

So if Checbox7 is selected (Subtotal + Tax) * .035

Translate
try67
Community Expert
Community Expert
Jun 9, 2020 8:38 AM UTC

And if it's not?

Translate
Jun 9, 2020 1:14 PM UTC

It is just 0 if not.

Translate
try67
Community Expert
Community Expert
Feb 19, 2017 8:54 AM UTC

What are the names of the check-box fields?

Translate
sw777
sw777Author
Known Participant
Feb 19, 2017 9:31 AM UTC

E101

E102

E104

E105

E107

F102

F104

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Feb 19, 2017 9:49 AM UTC

You can use this code as the custom calculation script of your CourseFee field:

var fields = ["E101", "E102", "E104", "E105", "E107", "F102", "F104"];

var total = 0;

for (var i in fields) {

    if (this.getField(fields).value=="Enrol") {

        total+=Number(this.getField(fields+"-fee").value);

    }

}

event.value = total;

Translate