Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JavaScript custom calculation script for a percentage

New Here ,
Mar 08, 2017 Mar 08, 2017

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.

TOPICS
Acrobat SDK and JavaScript , Windows
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 09, 2017 Mar 09, 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 09, 2017 Mar 09, 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%).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2017 Mar 09, 2017

try67 Thank you so much for providing this solution. I still have not got it working correctly, but I'm closer than where I was before.

-- I set the field Format as Percentage (previously I had missed this step).

-- I deleted *100 from the end of the formula in the custom calculation script.

-- Now when I test the form, the calculation is showing as 0.00%. I just cannot see why it will only come out to 0.00% instead of a true calculation.

I appreciate your time, thank you again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 10, 2017 Mar 10, 2017
LATEST

You need to change the value of one of the fields involved for it to kick-in.

Also, check the JS Console (Ctrl+J) for any error messages.

If you've done all of that and it's still not working then you'll need to share the actual file with us.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines