Skip to main content
Participating Frequently
March 23, 2020
Question

Calculations in Adobe Acrobat

  • March 23, 2020
  • 3 replies
  • 2429 views

I am trying to calculate the number of times N/A is selected from a drop down menu on each page to a total field on a form in Adobe Acrobat Pro DC. The current drop down options are 0, 1 and N/A. On one page, there is 1 column of down downs and I have the selection appearing in the total column to tally. The next page is 3 columns of 7 rows which total from left to write to a column to total the selection.

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
March 27, 2020

Is it "N/A" or "N / A"?

Can you share (part of) this form?

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
March 24, 2020

Place this script as a calculation script in the field that display the result:

 

var total = 0;
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "combobox") && (oFld.valueAsString == "N/A")) {total++;}
}

event.value = total;

 

Acrobate du PDF, InDesigner et Photoshopographe
HunniesAuthor
Participating Frequently
March 24, 2020

Thank you!  I initially received an error message and had to add ")" on line 4 however, I must have N/A still does not tally.  I even deleted the old total field that displays the results and created a new one and added the code.  I honestly don't know what else to do at this point. 

 

I do truly appreciate everyone for helping.

ls_rbls
Community Expert
Community Expert
March 23, 2020

Hi,
You need to use a "for loop" operation.


For this to work you need to make sure that allof the dropdown field names are prefixed; the prefixed part of the dropdown fieldname is used to perform the looping function correctly.


In your case, lets say that you have 3 columns of seven rows each, and each dropdown fieldname will be prefixed as "dropdown1" for the first 7 rows , "dropdown2" second set of rows, and "dropdown3 for the third set of rows.


The line of javascript code below is an example of how it may be used to calculate total number of dropdowns with "N/A" as the selected item.:

 

NOTE: I have not tested this successfully on my end but you can give it a try.

 

var v = "N/A"; 
var total = 0; 
for (var i=1; i<=7; i++) { 
if (this.getField("Dropdown1"+i).valueAsString==v) total++; 

} 
event.value = total;

 

HunniesAuthor
Participating Frequently
March 24, 2020

Thank you for helping me!  I've tried the code and it doesn't add the N/A's.  Just in case I'm not explaining it correctly.  Although N/A has no value in the total field, nor does 0 of course, near the bottom, I need to total the times N/A is selected from the drop downs.  The JavaScript code provided, I placed in properties for "Total N/A in 618" field in Custom Calculation Script.

 

 

Thom Parker
Community Expert
Community Expert
March 24, 2020

Thank you for reviewing.  With the three options of 0, 1 or N/A, I cannot add the export value of 1 for N/A otherwise when selecting N/A, the total field would be incorrect.  I have to leave 1 as 1, 0 as 0 and N/A would technically be 0 as the export value within the drop down as well.  Yet, I need to be able to tally the number of times someone selects N/A.


***Ok, so what exactly, at this time, is the export value of the "N/A" entry?

 

***Did you check the console window for errors?

 

I provided an alternate methodology for getting the selection, i.e., "field.currentValueIndices".

Here's the reference entry for this property:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_properties.htm%23TOC_currentValueIndicesbc-13&rhtocid=_6_1_8_31_1_12

 

 

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