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

Count number of checked boxes

New Here ,
Jan 25, 2022 Jan 25, 2022

Hello,

I am sure this topic has been asked many of times. Reviewing others solutions, I could not derive my own. I have three templates that have checkboxes for Met, Not Met, and N/A. At the bottom of the template there are boxes for Total Met, Total Not Met, and Total N/A. I would like for the total boxes to reflect the sum of the corresponding check marked boxes. See PDF attached.

 

I have 2 other templates that are similar but vary in the number of Met, Not Met, and N/A boxes. The communities help, would be greatly appreciated.

 

Thanks in advance!

TOPICS
Edit and convert PDFs , General troubleshooting , How to , PDF forms
2.9K
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 ,
Jan 26, 2022 Jan 26, 2022

For each row you should use 3 boxes with the same name and a different export value.
This would allow the user to make only one choice, and the calculation of totals would be simpler.

 

Capture_109.pngexpand image


PDF Acrobatic, InDesigner & Photoshoptographer
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
New Here ,
Jan 28, 2022 Jan 28, 2022

Thank you. Both suggestions were helpful. Naming all three boxes the same did result in allowing only one checked box. However, when I change the export to where I would like the total to go, it is blank. If I use the calculation function in the total box and set to met1, it counts all three boxes when one is checked.

 

When each box has its own name, it calculates fine, but that will be a tedious 100+modifications. Any suggestions?

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 ,
Jan 28, 2022 Jan 28, 2022

If you keep your naming like in your template (Met1, Met2, Met3...etc) you can use this script as custom calculation script of "Total Met" field:

var met = 0;
for( var i=1; i<=12; i++){
if(this.getField("Met"+i).valueAsString != "Off")met++;}
event.value = met == 0 ? "" : met;

 

Use same script for other fields just change field name in script.

If you have more then 12 fields change 12 to number of fields you have.

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
New Here ,
Feb 02, 2022 Feb 02, 2022

Not exactly sure what I am doing wrong. Could you share a few screen shots? All together I have 75 check boxes that need to be counted in batches of 15 (Met, Not Met, N/A).

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 ,
Feb 02, 2022 Feb 02, 2022

You can test it in this file, scripts are in totals field:

https://drive.google.com/uc?export=download&id=1CM6iXMuVReRrpmmSBlnHig0rx6BCuBTB 

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
New Here ,
Feb 03, 2022 Feb 03, 2022

Nesa,

Thank you. The example helped very much to understand and finish the project.

Michael

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 ,
Feb 03, 2022 Feb 03, 2022

In Nesa's example doc the checkboxes are not mutually exclusive, so the form will not operate correctly, i.e., someone could select all 3 options "Met", "Not Met", and "NA" on a single line, so you don't actually have a working solution.

 

 

 

 

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
Community Expert ,
Feb 02, 2022 Feb 02, 2022

You need to be specific about the details, What exactly are the names of your checkboxes?  

For the purposes of  the script I'll assume each checkbox in the row has the same name, and the rows are named "Met1", "Met2", etc.

 

Here is a calculation script for the total box under the "Met" column.

 

 

var nCount= 0, ;
var nNumRows = 15;
var cExport = "Met";

for( var i=1; i<=nNumRows; i++){
    oFld = this.getField("Met"+i);
    if(oFld && (oFld.value == cExport))
       nCount++;
}
event.value = nCount;

 

 

 

 

Now, to change this for the other columns, just change the "cExport" value. 

If you have different numbers of rows, then change the "nNumRows" value.

 

However, if I was doing this I'd do it a bit differently. 

First, good form design for scripting is all about structure. Especially when the form has some complexity. And structure is directly controlled by the field names. I'd use hierarchical group field naming to divide up the different groups of fields . For example the check boxes in met group would be named "MetChecks.MetGrp1.Row1", "MetChecks.MetGrp1.Row2",  etc. Then the total field at the bottom of the column would include the export value in it's name, like this: "MetChecks.MetGrp1.Total.Met", "MetChecks.MetGrp1.Total.NA", etc. Then I could write a single document level calculation script that would work for all total fields without knowing anything about how many rows of check boxes there were, or what the export value is, or even what the fields are named. 

 

 

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
New Here ,
Feb 04, 2022 Feb 04, 2022

Thanks Thom. You have to excuse my ignorance, this is new to me. I am huge fan of see one, do one to learn and execute. Could you provide an example in the template I had DL? There is no urgency and your guidance would be of value.

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 ,
Feb 05, 2022 Feb 05, 2022
LATEST

Sorry I didn't read where you asked for mutually exlusive checkboxes, must have missed it 🙂

anyway here is your file with mutually exclusive checkboxes, pay attention to checkbox naming and their export values, script is in "Total Met" field:

https://drive.google.com/uc?export=download&id=1PKmqvYxxi0glTwWfqmcxNt_kN88Vwew9 

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