Skip to main content
Participant
November 18, 2017
Question

Newbie Acrobat Pro user

  • November 18, 2017
  • 1 reply
  • 286 views

I am looking for something specific and have been unable to find it on the forums.  I am not even sure if it is feasible.  It isn't a requirement, it is a nice to have.

Basically I have a 3 page form that I created to assist those submitting requests to me to do them consistently and help mitigate the potential for inaccuracy.  It is a fairly simple form and I found some answers on the forums that helped me get it about 95% there.

Basically I would like something where the Total Cost box (on page 1 which is derived from a sum calculation from fields on page 2) will be divided by the number of fields with information entered in them from page 3 and show the results in a dollar value in the field Per Person Cost on page 1.

I have 38 total fields with two different naming conventions on page 3 that need to be included in a script.

PRINT NAME1 (it goes to PRINT NAME30

PRINT NAME 1_2 (it goes to PRINT NAME 8_2)

Hoping I have explained myself well enough.  To summarize:

Basically if 12 names are entered on page 3, the value shown in the Total Cost box on page 1 ( say $60.00) would be divided by 12 resulting in a Per Person Cost ($5.00) on page 1.

I apologize if this has been answered elsewhere, I couldn't find it.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
November 18, 2017

I would suggest grouping all the fields using the "dot" notation.  For example, "PrintName.1", "PrintName.2", "PrintName.1_2"

This naming provides an easy methodology for acquiring the fields you want to count.

If this naming is used, then put this calculation script in the 'PerCost' field

// Get list of fields to count

var aFldList = this.getField("PrintName").getArray();

var nCnt = 0;

// Count fields that are not empty

aFldList.forEach(function(a){if(!/^\s*$/.test(a.valueAsString))nCnt++;});

event.value = this.getField("Total Cost").value/nCnt;

I'm assuming the name for the total cost field is "Total Cost", change this to the correct name

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