Skip to main content
Participant
March 8, 2017
Question

JavaScript custom calculation script for a percentage

  • March 8, 2017
  • 1 reply
  • 3089 views

I have created a fillable PDF form in Acrobat Pro DC that needs to tally the scores (on a scale of 1-5) given in several text fields (I used radio buttons), divide it by the total score possible (25) and display it at the end of the form as a percentage. I was told I need a JavaScript custom calculation script. Originally I tried using a simplified field notation, but that did not work. Can anyone help convert this formula to a custom calculation script: ((sum1+sum2+sum3+sum4+sum5)/25)*100.

Thank you for your time.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
March 9, 2017

You can use this code:

var sum = Number(this.getField("sum1").value) + Number(this.getField("sum2").value) + Number(this.getField("sum3").value) +

     Number(this.getField("sum4").value) + Number(this.getField("sum5").value);

event.value = (sum/25)*100;

try67
Community Expert
Community Expert
March 9, 2017

PS. If you set the field as having a Percentage formatting then you shouldn't multiply by 100. The value needs to be between 0 (0%) and 1 (100%).