Copy link to clipboard
Copied
Ok, there is probably a painfully obvious answer to this question, but I can't figure it out. I have a list with 400+ checkboxes next to each item. When I activate (i.e., click and check) any particular checkbox, they change appearance to now show a check inside the box. So far so good. But I also want to increment another field which tracks how many boxes have been checked. Of course, unchecking any box will decrement that counter so if no boxes are checked the counter displays 0.
I used InDesign 2020 to create this list and all the checkboxes, but can switch to Acrobat if that makes things easier.
How the heck do I do this?
Copy link to clipboard
Copied
Hi,
If you want to count all the checkbox fields:
var total=0;
for (var i=0; i<this.numFields; i++) {
var fname=this.getNthFieldName(i);
if (fname.type="checkbox" && fname.value!="Off") total++;
}
console.show();
console.clear();
console.println("Number of checked boxes: "+total);
@+
Copy link to clipboard
Copied
You will need to add this code to the PDF form with Acrobat Professional.
A very important component of this scirpt is the names of the check boxes. It has to follow a regular pattern.
You'll find a video tutorial here on using the Acrobat Console Window:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
However, the console is for testing, debug, and one off scripts. You need to place the script for adding your check boxes into a calculation for the field where the sum will be displayed.
This question has been asked before. Here is a search on this forum for "Count Checkbox"
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi,
If you want to count all the checkbox fields:
var total=0;
for (var i=0; i<this.numFields; i++) {
var fname=this.getNthFieldName(i);
if (fname.type="checkbox" && fname.value!="Off") total++;
}
console.show();
console.clear();
console.println("Number of checked boxes: "+total);
@+
Copy link to clipboard
Copied
Thank you, this looks like what I need. Problem is, I don't know where to put this code nor how I call the script when I need it. Can you please clarify? Obviously this is failry new to me... I have never needed to make an interactive PDF before. You patience with me is much appreciated.
Copy link to clipboard
Copied
You can copy/paste the script into the console, then select all the script and enter key
please try!
@+
Copy link to clipboard
Copied
Again, I am too new at this and am feeling a bit silly. What (and where) is "the console"? I have Acrobat open but just don;t see that anywhere. (Experienced Acrobat users please excuse my substantial stupidity).
Copy link to clipboard
Copied
Type ctrl J
Copy link to clipboard
Copied
Again, my apologies. I do not understand how to connect the script you provided with the PDF I am building. I can paste it in the console, but where does the result actually get displayed? In other words, when I check three of the 400 boxes, where is the "3" shown on the PDF?
Thanks very much for your patience.
Copy link to clipboard
Copied
You will need to add this code to the PDF form with Acrobat Professional.
A very important component of this scirpt is the names of the check boxes. It has to follow a regular pattern.
You'll find a video tutorial here on using the Acrobat Console Window:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
However, the console is for testing, debug, and one off scripts. You need to place the script for adding your check boxes into a calculation for the field where the sum will be displayed.
This question has been asked before. Here is a search on this forum for "Count Checkbox"
Use the Acrobat JavaScript Reference early and often

