# How to calculate the number of checked checkboxes??

New Here ,
Jan 18, 2017 Jan 18, 2017

Copied

I have 90 check boxes in a pdf form. I want to calculate the total number of check boxes being checked in the form and show the result automatically in the "total" field. How can I do that? I do not know about scripts. Please help. Thank you!

TOPICS
PDF forms, Windows

Views

4.4K

Likes

Report

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

Most Valuable Participant , Jan 19, 2017 Jan 19, 2017
Use this code as the custom calculation script of the "total" field:var total = 0;for (var i=1; i<=90; i++) {    if (this.getField("cb"+i).value!="Off") total++; }event.value = total;

Likes

9 Replies 9
Most Valuable Participant ,
Jan 19, 2017 Jan 19, 2017

Copied

Use this code as the custom calculation script of the "total" field:

`var total = 0;for (var i=1; i<=90; i++) {    if (this.getField("cb"+i).value!="Off") total++;}event.value = total;`

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jan 19, 2017 Jan 19, 2017

Copied

Sorry try67! I'm very stupid at JS. I've input the script and no result shown. Did I make it wrong?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Jan 20, 2017 Jan 20, 2017

Copied

Did you enter it under the field's action, as I've described, or did you use the Edit All JavaScripts command? If the latter, you may have corrupted the file...

Likes

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 Beginner ,
Mar 20, 2021 Mar 20, 2021

Copied

Thank you - this is working perfectly. My problem is that I'm working in pages in pdf. It works wonderfly for page 1, but when it comes to page 2, I've followed the same 'formula' and renamed my check boxes but it simply won't calculate my boxes. Should I be adding in a page number reference somewhere in the above javascript somewhere to indicate its on a different page, etc.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Mar 20, 2021 Mar 20, 2021

Copied

LATEST

No, the page it's on doesn't matter. Check the JS Console for error messages. If you can't find a solution share the file and we'll help you out with it further.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jan 22, 2017 Jan 22, 2017

Copied

I've entered it under the field's action. But when I debug the script, it shows the following error.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Jan 22, 2017 Jan 22, 2017

Copied

You are not using the correct field name to get the field objects. JavaScript is case sensative.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jan 22, 2017 Jan 22, 2017

Copied

Thank you try67!! I know the problem now..... As I have revised the file many times and it is corrupted as you said. I used the original file and enter the script again and it works!!

Thank you very much!!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Oct 26, 2020 Oct 26, 2020

Copied

Hi all, is there a way to have the total box be blank rather than show a 0   when nothing is selected?

Likes

Report

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