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

JavaScript Count If Checked

New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

I have a page with a grid of checkboxes -- columns and rows. 

 

I'd like a field to the right of the row that gives me just a total of the number of checkboxes checked across the row (checkbox1, checkbox2, checkbox3, checkbox4, checkbox5). 

 

I realize if I want to total up the row's checked boxes the calculation would be the same as if I checked a column's checkboxes, the only difference being how I indicate which fields are being counted conditionally. 

 

Anyone that can help me with this?

 

Thanks in advance! 

TOPICS
Acrobat SDK and JavaScript

Views

1.5K

Translate

Translate

Report

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

correct answers 1 Correct answer

Explorer , May 20, 2020 May 20, 2020

I figured this out. I solved it by making sure each checkbox had a different exported value other than "Yes". I gave them the exported value of 1.

Checkbox Export Value@2x.png

 Then I had a text field at the end of the row, and at the bottom of the column, that calculated the sum of the corresponding checkbox fields for that row or column. 

Votes

Translate

Translate
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

 

An easy way to count checked checkboxes is to name them so that the checkbox names can be automatically found from the name of the total field.  Then a generic script can be written to automatically generate the names. 

 

For example "Row1_Col1"  "Row1_Col2" "Row1_Col3" ....  "Row1_Total"

 

Do you have any scripting experience?

These are also called table calculations. Serarch for this word on the forum and you'll find other threads that discuss specific code.

You can read more about general form scripting. Watch the video on Field Naming:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

 

 

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

Votes

Translate

Translate

Report

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 ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

I was logged in with the wrong account when I posted this originally. Replying here with my proper account. 

 

I have limited experience with scripting so I didn't understand your reply, but maybe I should have been a little more clear with my post to begin with. My table ONLY has checkboxes, no fields with numbers. Here's how it looks: PDF Checkbox Calc@2x.png

In that column to the far right, I want to put a numeric field that simply tells me how many boxes were checked across the cooresponding row. Not sure this changes your suggestion to me...

Votes

Translate

Translate

Report

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 ,
May 20, 2020 May 20, 2020

Copy link to clipboard

Copied

LATEST

I figured this out. I solved it by making sure each checkbox had a different exported value other than "Yes". I gave them the exported value of 1.

Checkbox Export Value@2x.png

 Then I had a text field at the end of the row, and at the bottom of the column, that calculated the sum of the corresponding checkbox fields for that row or column. 

Votes

Translate

Translate

Report

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