Copy link to clipboard
Copied
This is probably really basic but Ive been teaching myself Java script via Google and YouTube. I'm learning a lot but I hit a wall. I have a section of a pdf with 36 rows and several columns. (Only 4 columns matter here). The student enters each course (title) they completed in column 1. They enter how many units the course was in another column. I'm a third column is a checkbox they select only if the course was a history course. In a fourth column is a checkbox they only select if the course is a math course: I need three totals beneath the list of courses. Total History units, total math units and total of all units including those not either history or math. .afding just the the history or math units based on the if a certain checkbox was selected in each row is what's stumping me. Can someone point me in the right direction?
Copy link to clipboard
Copied
An important part of scripting forms, and especially scripting tables of fields, is coming up with a scheme to name the fields. A good naming scheme can massively simplify the scripting.
There's lots of good info on scripting PDF forms here:
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm
In this case the fields should be named colum first, for supporting the summation process.
For example, "Units.Row1", "Units.Row2", etc, and "HistoryChk.Row1", "HistoryChk.Row2", etc.
Then the rows can be looped using this syntax.
// This is a calculation script for the field that sums the total units.
var nSum = 0;
this.getField("Units").getArray().forEach(function(oFld){nSum += Number(oFld.value);});
event.value = nSum;
This is just a simple script showing the basics. The script on the form should include some testing for a valid input value.
The checkboxes are handled slightly differently. You can read about it here:
https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm
Copy link to clipboard
Copied
If you can tell us naming of the fields or even better share your file with us, we can help you easier.
Copy link to clipboard
Copied
The easiest way to do this is to first create one row only. Then select all the fields, right-click one and select Create multiple copies, and enter the number of rows. Before you do this enter 1 as the export value of the check boxes. The fields in row 1 will be renamed with a .0 suffix. The renaming fields will be renamed with a continuous numbering suffix starting with .1 through .20 (assuming 21 rows). When you create fields for totals at the bottom, in the Calculate tab, select Sum of. You only need to select the orginal field (without the suffix) for each column, and not every field in that column. The checkboxes will only total the ones that are checked. Here's a couple articles (with video) on the check box part:
https://pdfautomationstation.substack.com/p/pdf-check-box-field-math
https://pdfautomationstation.substack.com/p/create-a-check-box-scoring-questionnaire
In this case I would suggest 2 hidden columns for history units and math units which would multiply the number of units by the corresponding check box if the check box is selected (use the same check box name in each row and set the export values to History and Math). You can set the formulas in the fields of the first row and anticpate what the field names will be after Create multiple copies.
https://pdfautomationstation.substack.com/p/anticipating-field-names-in-custom
Copy link to clipboard
Copied
Wow. This will be fun to learn these new tricks! Thank you for the guidance. I really appreciate it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now