Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Checkboxes and sequential numbering

Explorer ,
Dec 16, 2019 Dec 16, 2019

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?

TOPICS
How to , PDF forms
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Dec 16, 2019 Dec 16, 2019

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);

@+

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2019 Dec 16, 2019
LATEST

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"

https://community.adobe.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2019 Dec 16, 2019

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);

@+

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2019 Dec 16, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2019 Dec 16, 2019

You can copy/paste the script into the console, then select all the script and enter key

please try!

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2019 Dec 16, 2019

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2019 Dec 16, 2019

Type ctrl J

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2019 Dec 16, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2019 Dec 16, 2019
LATEST

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"

https://community.adobe.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines