Skip to main content
Frank Sobolewski
Participating Frequently
December 20, 2019
Question

Require javascript formula to determine percentage in Acrobat DC Pro form

  • December 20, 2019
  • 1 reply
  • 778 views

I have a form that requires percentage to be calculated using values input by person filling form.

Text4.0 is no. of attendees

Text4.1 is no. of Employees

Text 4.2 is the percentage calculation

This topic has been closed for replies.

1 reply

Inspiring
December 20, 2019

For the case of the number of employees being non-zero, I would divide the number of attendees by the number of employees. I would set the field format to the percentage display format and specify the number of decimal places to display. Acrobat JavaScript considers division by zero to result in Not a Number or NaN. One can only use the Custom JavaScript calculation method.

 

// get computational  values;

var nAttendees = this.getField("Text4.0").value;
var nEmployees = this.getField("Text4.1").value;

event.value = 0;

// clear result field;

if(nEmployees != 0){

// compute if divisor not zero;
event.value = nAttendees / nEmployees
}

Frank Sobolewski
Participating Frequently
December 20, 2019

That works great! Thanks for the information. 

 

This may be ao ongoing requirement for my business. Do you have a suggestion as to how I can either

a) learn how to do this

b) contract someone to do this. 

 

Thanks again!!!

Thom Parker
Community Expert
Community Expert
December 20, 2019

Here is a site all about Acrobat Scripting (there's plenty of free material to look over):

https://www.pdfscripting.com/public/main.cfm

 

For contract work, contact me:

http://www.windjack.com/

 

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