Skip to main content
Known Participant
May 25, 2021
Answered

Help with script to calculate a text field in interactive PDF

  • May 25, 2021
  • 1 reply
  • 5000 views

Hi, I'm generating an interactive form for a sales team. They want to auto calculate a goal percentage

EG: Put in a field your $$ target, then another field your current $$ earnings. Then another box calculates the % of how close you are to your goal (i.e 73%)

My PDF has defined text fileds. Can anyone help with a code for 

Q1_2 divided by Q1 times by 100 (to give me a %)

Thank you

This topic has been closed for replies.
Correct answer Nesa Nurani

If you want to see how close you are to the goal, shouldn't you just divide earnings by your target?

Anyway you can use custom calculation script of percentage field, something like this ( change final calculation if you need something else):

var q1 = Number(this.getField("Q1").value);
var q2 = Number(this.getField("Q1_2").value);
if(q1 == "" || q2 == "") event.value = "";
else event.value = q2/q1;

1 reply

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
May 25, 2021

If you want to see how close you are to the goal, shouldn't you just divide earnings by your target?

Anyway you can use custom calculation script of percentage field, something like this ( change final calculation if you need something else):

var q1 = Number(this.getField("Q1").value);
var q2 = Number(this.getField("Q1_2").value);
if(q1 == "" || q2 == "") event.value = "";
else event.value = q2/q1;

Known Participant
May 25, 2021

Thanks for your help. When I pasted your code the PDf preview of that box now shows NaN?

 

Nesa Nurani
Community Expert
May 25, 2021

Did you format fields?

The problem is probably because you didn't format fields and you enter numbers like this: 523,988 you should enter it with a dot like this: 523.988 or format fields.