These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Conditional Calculation of Range based on Checkboxes

Thr33of4
Registered: Jul 23 2010
Posts: 5
Answered

My wife just started a bookkeeping business and she's trying to design a vendor report form that has a vendor listed and the amount of money owed to said vendor.

Her clients don't pay all the vendors every time, so she'd like to include a checkbox on whether or not to pay that vendor. She'll send the form to her client, the client will check the checkbox on the vendors to be paid and the total box at the bottom will tally all vendor amounts with checked boxes.

The set up of the form will be very simple. Checkbox | Vendor Name | Description of charge | Charge
then at the bottom there will be a Total Charges field and a Total Paid field. I'd like the Total Paid field to be where the javascript is located.

This is my first attempt at javascript, but I'm decent at VBA and Excel/Access so I understand the basic syntax behind javascript. That having been said, my dilemmas are:

1) How will I associate the check box with the Charge field
2) How do I specify the range of 'Charge' fields so the javascript can look through to see if the checkbox has been checked for that specific dollar amount

I've searched the forum for Conditional Calculation, read the article on Conditional Execution by ThomP as suggested by people in the forum, but haven't seen anything related to this specific dilemma.

Thanks in advance.

My Product Information:
Acrobat Pro Extended 9.2, Windows
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
I would do something along these lines:

- When setting up the form, give the check-boxes and charge fields a similar name, something like this:
CB1 .... Charge1
CB2 .... Charge2
CB10 ... Charge10
This is just good practice in general, but it will also come in handy for the total calculation, as you'll see now.

- For the Total charge field, create a custom calculation script that uses a loop to go over all the check-boxes, checking if they are checked, and if so adding them to the total. Something like this:
totalCharge = 0;for (i=1; i<=10; i++) {if (this.getField("CB"+i).value=="Yes") totalCharge+=this.getField("Charge"+i).value;}event.value = totalCharge;

I'm assuming here there are ten rows in the form. You can of course change that, as well as the value of the checked check-box (I used "Yes" in this example).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Thr33of4
Registered: Jul 23 2010
Posts: 5
Worked perfect. Thanks!