These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Counting formula for checkboxes

RacyStacey
Registered: Nov 2 2009
Posts: 2

I have a form that has a bank of 28 checkboxes, these do not have a numerical value as they're crossed or not.

In excel I'd use a simple count formula but this will obviously require a JS in Acrobat. I have absolutely no idea how to do this and would greatly appreciate any help anyone can offer me.

I'm using Acrobat 9 Pro and windows.

Thanks in advance,

Stacey

P.S. - I used the search function but couldn't make adapt any of the other posts containing JS.

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Counting form elements is fairly simple, but it requires that the fields are named in a way that makes them easy to use for this task. The best method is to group fields with the "dot" notation. For example, name all your fields "MyChecks.Q1", "MyChecks.Q2", "MyChecks.Q3", etc.

This code can be used to count the number that have been checked. Place it in a Custom Calculation Script for a text box.
var nSum = 0;var aCkFlds = this.getField("MyChecks").getArray();for(var i=0;i<aCkFlds.length;i++){if(aCkFlds[i].isBoxChecked(0))nSum++;}event.value = nSum;

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

JVOS
Registered: Apr 2 2010
Posts: 2
I've recently used the following to count checked boxes:

Scenario - 13 questions with checkboxes A & B.1) Define a Total field for each - CheckedA & ChedkedB
2) Each checkbox property:
- exports value 1 when checked
- runs JS on MouseDown (CheckedA++) or (CheckedB++)
3) Total fields (CheckedA, CheckedB) calculate sum of their associated boxes.

This totals all of the A's checked and all of the B's checked - will also subtract when box is unchecked.
patsydelk
Registered: Dec 28 2010
Posts: 11
Thomp, your script works for 1 checked box. I have a total of 6 that
can be checked. I need the script to add all checked bxs, then multiply
the total by 1500. This is what I've come up with so far, but there is an
error in it: var nSum=
this.getField("Box.1").getArray()+;this.getField("Box.2").getArray()+;this.getField("Box.3").getArray()+;this.getField("Box.4").getArray()+;this.getField("Box.5").getArray()+;this.getField("Box.6").getArray()+;for(var i=0;i
patsydelk
Registered: Dec 28 2010
Posts: 11
Sorry Thom, your script is perfect. Operator error on my part.