Highlighted

Tallying Check Boxes

Community Beginner ,
Nov 09, 2020

Copy link to clipboard

Copied

I have a doc that I am trying to calculate the check boxes. I have a text field that I have checked all the correct check boxes under value is.  All my check boxes have a value of 1 but when I try the calculation a few of the checks have a value of 1 then they go to a value of 2 and then a value of three.  I have 70 check boxes on one chart so I didn't want to write a java schript for every field.  This is a basic 4x14 chart and I am needing totals at the end of each column. All values of checks are 1. Help please

TOPICS
PDF forms

Views

82

Likes

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

Tallying Check Boxes

Community Beginner ,
Nov 09, 2020

Copy link to clipboard

Copied

I have a doc that I am trying to calculate the check boxes. I have a text field that I have checked all the correct check boxes under value is.  All my check boxes have a value of 1 but when I try the calculation a few of the checks have a value of 1 then they go to a value of 2 and then a value of three.  I have 70 check boxes on one chart so I didn't want to write a java schript for every field.  This is a basic 4x14 chart and I am needing totals at the end of each column. All values of checks are 1. Help please

TOPICS
PDF forms

Views

83

Likes

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
Nov 09, 2020 0
Contributor ,
Nov 09, 2020

Copy link to clipboard

Copied

You have 4 columns with 14 checkboxes in each column?

You want to count checked checkboxes in each column?

What are the names of checkboxes?

Likes

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
Reply
Loading...
Nov 09, 2020 0
Community Beginner ,
Nov 09, 2020

Copy link to clipboard

Copied

Mblty1.0.0, Mblty1.0.1, Mblty1.0.2,  Mblty1.0.3.0, Mblty1.0.3.1, Mblty1.0.3.2, Mblty1.0.3.3, Mblty1.0.3.4.0, Mblty1.0.3.4.2, Mblty1.0.3.4.3, Mblty1.0.3.4.4, Mblty1.0.3.4.5, Mblty1.0.3.4.6, Mblty1.0.3.4.7

Likes

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
Reply
Loading...
Nov 09, 2020 0
Community Beginner ,
Nov 09, 2020

Copy link to clipboard

Copied

Yes, in the column that the check is in. I would like the amount of check marks calculated in that column.  I wanted these to be radio buttons because only one answer will be in a row but that seemed more difficult than this.

Likes

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
Reply
Loading...
Nov 09, 2020 0
Adobe Community Professional ,
Nov 09, 2020

Copy link to clipboard

Copied

You have a couple of different options. The simple method is to do what you are already doing.  Give each checkbox an export value of 1, then use the "Sum" calculation to add up the boxes in each column.

 

The other option is to write a generic script for adding the values. In this scenario you'll need to use radio buttons. Give each radio button a set of exports that indicate the column, such as Col1, Col2, etc. 

 

Let's say the radio button groups are named "MyRadio.Row1", "MyRadio.Row2", etc. This type of group naming is critical to making a generic script that will work for every column. 

 

Here's the calculation script. It's exactly the same for each sum field, except for the name of the Column that is being added, and if you have more than one table, then the group name for the radio buttons is different. 

 

var cColName = "Col1"; // Add up column 1 radio buttons
var cFldGroupName = "MyRadio";
var nSum = 0; 
this.getField(cFldGroupName).getArray().every(function(){if(a.value==cColName)nSum++;});
event.value = nSum;

 

Likes

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
Reply
Loading...
Nov 09, 2020 0
Community Beginner ,
Nov 09, 2020

Copy link to clipboard

Copied

So I think the radio buttion are above my head.  Going back to what I was origionally doing it is not calculating correctly.  It is giving different values to my checks other than 1.  I have checked them all and they all have an export value of 1.  

 

About the script above....I'm not sure what info that I put in that formula or where to put it.

Likes

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
Reply
Loading...
Nov 09, 2020 0
Adobe Community Professional ,
Nov 09, 2020

Copy link to clipboard

Copied

Can you post the form? I'm not sure I understand what you mean by not calculating correctly and seeing exactly what it is that is being done will clear it up. 

 

Acrobat will not change the value of your checkbox export. However, there can be issues with how they get added up. This is what we need to see.

 

Likes

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
Reply
Loading...
Nov 09, 2020 0
Community Beginner ,
Nov 10, 2020

Copy link to clipboard

Copied

prop of check marks.JPGcheck marks.JPGText box.JPG

Likes

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
Reply
Loading...
Nov 10, 2020 0
Community Beginner ,
Nov 10, 2020

Copy link to clipboard

Copied

I'm only working on the first column then I will move forward.

The first three export a value of 1

4 - 7 export a value of 2

8 - 14 export a value of 3

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

Are you saying that the export for rows 4-7 changed to 2, on it's own, after you set it?

 

If it changed there must be another script on the form that is doing this, or something else is going on. Fields don't change on thier own. 

 

This would all make more sense if you could post the actual form. If it contains confidential information, then copy the form fields of interest to a new blank  PDF and post that.

 

 

 

 

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

The method that the OP is using was answered correctly by Asim in a recent thread but it was much more simpler in terms of radio buttons. In this case the user is trying to employ radio buttons as a table.

 

It happened to me too when I recreated this scenario with radio buttons and checkboxes alike. 

 

The problem triggers when the Acrobat's  built-in "value is sum(+)" feature is currently employed in the totaling field with the groups of radio buttons (or checkboxes), specifically when the fields weree created as mutually exclusive (same field name, different export value on each).

 

Although according to the screenshots provided it seems like every field has a different fieldname, it is possible that the conflict occurs with how they were created as a group.

 

I would say, that if you're treating checkboxes as radio buttons, or checkboxes to behave as radio buttons to avoid doing that.

 

It is better if you just create one checkbox with an export value of 1. Then create the multiple copies.. The problem with this is what the OP mentioned, you won't be able to switch betwen columns as you would with a group of 4 radio buttons per row. The user must uncheck 

 

 

If that makes any sense.

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

This explanation doesn't even come close to explaining why an export value would change, or the calculation would add incorrectly. 

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

Sorry my explanation didn't came out right.

 

I was not referring to the export values changing on its own on each radio button or checkbox , but how the exports values are tallied based on the current arrangement of checkboxes groups (or radio buttons groups) on each row.

 

I was aiming at this particular comment: 

 

"Yes, in the column that the check is in. I would like the amount of check marks calculated in that column.  I wanted these to be radio buttons because only one answer will be in a row but that seemed more difficult than this."

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

Seems to me like some field names are repeated on that table.

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

I agree that it is entirely possible that there are repeated field names and/or mis-set export values. There is lots of room for user error, but without actually looking at the form it is impossible to tell.  

Likes

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
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

This what I was able to come up with.

 

See the slide:

 

radios.png

 

You need to create one radio button first and set an export value of 1.

 

Keeping in mind that radio buttons work in pairs, but we are doing mutually exclusive group of 4 radio buttons per row,  the first thisng you must do is right-click on that radio button-->> select "Create Multiple Copies" from the context menu and generate the first column only. So select "Copy selected fields down" and do 14.

 

You'll need to rename each field (in ascending order of course), after you perform this action before you move to the rows step; shown in the next sldie:

 

more-radios.png

 

And now you select all of those fields,  right-click again to select "Create Multiple Copies" again, and choose "Copy selected fields accros"  4.

 

This will generate your radio button table in the appropriate order for this calculation to work correctly.

 

more-radios2.png

 

Now, the fun part!

 

For this to work you'll need to use a custom calculation script (an Array()  method is not exclusively necessary and the built-in Acrobat's "value is sum(+)" feature won't work because it won't understand the zero-based index that is involved in an array of fields like this case with checkboxes and radio buttons.

 

NOTE: In JavaScript, when you work with a group of objects, such as radio buttons, by which the same name is used for each field  (but a different export value),  the first button in a row is indexed as 0, the second as 1, the third as 2, the fourth as 3, and so on. The same applies for counting pages in a document via script. The first page would start at 0, not 1, for example.

 

 

For the total fields under each column I declared my variables as Rb1Col1 (to refer to the first radio button group in the first row under the first column). And I employed  "isBoxChecked" in this script to determine if the radio button widgets are checked or  unchecked before the calculating event is called for (I am not using the "getField" method here to obtain the export values, nor valueAsString methods) :

 

With that NOTE in mind, this is how the calculation script would look like in the total field under the first column:

var Rb1Col1 = this.getField("Mblty1").isBoxChecked(0);
var Rb2Col1 = this.getField("Mblty2").isBoxChecked(0);
var Rb3Col1 = this.getField("Mblty3").isBoxChecked(0);
var Rb4Col1 = this.getField("Mblty4").isBoxChecked(0);
var Rb5Col1 = this.getField("Mblty5").isBoxChecked(0);
var Rb6Col1 = this.getField("Mblty6").isBoxChecked(0);
var Rb7Col1 = this.getField("Mblty7").isBoxChecked(0);
var Rb8Col1 = this.getField("Mblty8").isBoxChecked(0);
var Rb9Col1 = this.getField("Mblty9").isBoxChecked(0);
var Rb10Col1 = this.getField("Mblty10").isBoxChecked(0);
var Rb11Col1 = this.getField("Mblty11").isBoxChecked(0);
var Rb12Col1 = this.getField("Mblty12").isBoxChecked(0);
var Rb13Col1 = this.getField("Mblty13").isBoxChecked(0);
var Rb14Col1 = this.getField("Mblty14").isBoxChecked(0);

event.value = Rb1Col1 + Rb2Col1 + Rb3Col1 + Rb4Col1 + Rb5Col1 + Rb6Col1 + Rb7Col1 + Rb8Col1 + Rb9Col1 + Rb10Col1 + Rb11Col1 + Rb12Col1 + Rb13Col1 +  Rb14Col1;

 

This how to use the same script in the total field under column 2:

 

var Rb1Col2 = this.getField("Mblty1").isBoxChecked(1);
var Rb2Col2 = this.getField("Mblty2").isBoxChecked(1);
var Rb3Col2 = this.getField("Mblty3").isBoxChecked(1);
var Rb4Col2 = this.getField("Mblty4").isBoxChecked(1);
var Rb5Col2 = this.getField("Mblty5").isBoxChecked(1);
var Rb6Col2 = this.getField("Mblty6").isBoxChecked(1);
var Rb7Col2 = this.getField("Mblty7").isBoxChecked(1);
var Rb8Col2 = this.getField("Mblty8").isBoxChecked(1);
var Rb9Col2 = this.getField("Mblty9").isBoxChecked(1);
var Rb10Col2 = this.getField("Mblty10").isBoxChecked(1);
var Rb11Col2 = this.getField("Mblty11").isBoxChecked(1);
var Rb12Col2 = this.getField("Mblty12").isBoxChecked(1);
var Rb13Col2 = this.getField("Mblty13").isBoxChecked(1);
var Rb14Col2 = this.getField("Mblty.14").isBoxChecked(1);

event.value = Rb1Col2 + Rb2Col2 + Rb3Col2 + Rb4Col2 + Rb5Col2 + Rb6Col2 + Rb7Col2 + Rb8Col2 + Rb9Col2 + Rb10Col2 + Rb11Col2 + Rb12Col2 + Rb13Col2 +  Rb14Col2;

 

This for the total field under column 3: 

 

var Rb1Col3 = this.getField("Mblty1").isBoxChecked(2);
var Rb2Col3 = this.getField("Mblty2").isBoxChecked(2);
var Rb3Col3 = this.getField("Mblty3").isBoxChecked(2);
var Rb4Col3 = this.getField("Mblty4").isBoxChecked(2);
var Rb5Col3 = this.getField("Mblty5").isBoxChecked(2);
var Rb6Col3 = this.getField("Mblty6").isBoxChecked(2);
var Rb7Col3 = this.getField("Mblty7").isBoxChecked(2);
var Rb8Col3 = this.getField("Mblty8").isBoxChecked(2);
var Rb9Col3 = this.getField("Mblty9").isBoxChecked(2);
var Rb10Col3 = this.getField("Mblty10").isBoxChecked(2);
var Rb11Col3 = this.getField("Mblty11").isBoxChecked(2);
var Rb12Col3 = this.getField("Mblty12").isBoxChecked(2);
var Rb13Col3 = this.getField("Mblty13").isBoxChecked(2);
var Rb14Col3 = this.getField("Mblty14").isBoxChecked(2);

event.value = Rb1Col3 + Rb2Col3 + Rb3Col3 + Rb4Col3 + Rb5Col3 + Rb6Col3 + Rb7Col3 + Rb8Col3 + Rb9Col3 + Rb10Col3 + Rb11Col3 + Rb12Col3 + Rb13Col3 +  Rb14Col3;

 

And last, for the total field under column 4:

 

var Rb1Col4 = this.getField("Mblty1").isBoxChecked(3);
var Rb2Col4 = this.getField("Mblty2").isBoxChecked(3);
var Rb3Col4 = this.getField("Mblty3").isBoxChecked(3);
var Rb4Col4 = this.getField("Mblty4").isBoxChecked(3);
var Rb5Col4 = this.getField("Mblty5").isBoxChecked(3);
var Rb6Col4 = this.getField("Mblty6").isBoxChecked(3);
var Rb7Col4 = this.getField("Mblty7").isBoxChecked(3);
var Rb8Col4 = this.getField("Mblty8").isBoxChecked(3);
var Rb9Col4 = this.getField("Mblty9").isBoxChecked(3);
var Rb10Col4 = this.getField("Mblty10").isBoxChecked(3);
var Rb11Col4 = this.getField("Mblty11").isBoxChecked(3);
var Rb12Col4 = this.getField("Mblty12").isBoxChecked(3);
var Rb13Col4 = this.getField("Mblty13").isBoxChecked(3);
var Rb14Col4 = this.getField("Mblty14").isBoxChecked(3);

event.value = Rb1Col4 + Rb2Col4 + Rb3Col4 + Rb4Col4 + Rb5Col4 + Rb6Col4 + Rb7Col4 + Rb8Col4 + Rb9Col4 + Rb10Col4 + Rb11Col4 + Rb12Col4 + Rb13Col4 +  Rb14Col4;

 

 

The "isBoxChecked" method  is explained in great detail with examples in  the  Adobe Acrobat SDK JavaScript API- JavaScript™ for Acrobat® API Reference , "Field methods"

 

See this part in Page 419:

 

isBoxChecked

 

Determines whether the specified widget is checked.
Note: For a set of radio buttons that do not have duplicate export values, you can get the value, which is equal to the export value of the individual widget that is currently checked (or returns an empty string, if none is).
Parameters

 

But in my examples illustrated earlier I am using duplicate export value of "1" on every radio button.

 

 

 

Likes

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
Reply
Loading...
Nov 10, 2020 1
Community Beginner ,
Nov 11, 2020

Copy link to clipboard

Copied

Thank you so much for all the detailed information.  I think I can get this project completed now.

Likes

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
Reply
Loading...
Nov 11, 2020 1
ls_rbls LATEST
Adobe Community Professional ,
Nov 11, 2020

Copy link to clipboard

Copied

You're very welcome.

Likes

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
Reply
Loading...
Nov 11, 2020 0
Engaged ,
Nov 11, 2020

Copy link to clipboard

Copied

You could name your checkboxes like this:
First row Check1, second row Check2, third row Check3...etc up to 14 rows in each row give them export value of A,B,C and D
so every checkbox in first column will have export value of A, second column B...etc.
Then in each text field (Custom Calculation Script) under apropriate column use this code:
var result = "";
for(var i=1; i<=14; i++){
if(this.getField("Check"+i).valueAsString=="A")result++;}
event.value = result;
Just change A to B,C and D in code in fields under each column:
See this example pdf 

Likes

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
Reply
Loading...
Nov 11, 2020 1