Skip to main content
November 14, 2017
Answered

PDF if, then statement: need help please!

  • November 14, 2017
  • 1 reply
  • 625 views

Hello, I need help creating a script to allow me to average two cells, only if one of them is greater than zero. I have the following cells: "TotalRatingUC", "TotalRatingLC", and "Overall Rating". We'll call it the following for simplification: TotalRatingUC=A, TotalRatingLC=B, Overall Rating=C.

So basically, i need C= A+B/2 if B>0. If B=0, i need C=A. I tried going off of other examples i found online, but the script i'm using is giving me an error message of: "SyntaxError:illegal charater 2: at line 3.

I was trying this:

if (this.getField("TotalRatingLC").value == '0') {
event.value = (this.getField(“TotalRatingUC”).value
} else {
event.value = (this.getField(“TotalRatingUC”).value + (this.getField(“TotalRatingLC).value / 2
}

Any thoughts? This is literally the last item i need to finish this pdf for my work.

Thanks in advance!

This topic has been closed for replies.
Correct answer gkaiseril

See the following script:

//  custom calculation script OverallRating
if (this.getField("TotalRatingLC").value == 0) {
event.value = this.getField("TotalRatingUC").value;
} else {
event.value = (this.getField("TotalRatingUC").value + this.getField("TotalRatingLC").value) / 2;
}

Changed comparison form comparing a number to a string to comparing two numbers.

Removed unbalanced "(" and change smart quotation marks to dumb quotation marks.

Changed calculation from adding UC to LC divided by 2 to dividing the sum of UC and LC by 2.

If LC and UC fields are calculated you might have an issue with the calculation order of the fields.

The JavaScript console told you the line number in the script and the character count in where it determined an error, in this case a missing ending ")".

There are many free references and tutorials about using Acrobat JavaScript.

1 reply

Inspiring
November 14, 2017

You need to remove unbalanced parenthesis.

November 14, 2017

I'm not very good at this....I've tried removing a few but nothing is working.

gkaiserilCorrect answer
Inspiring
November 15, 2017

See the following script:

//  custom calculation script OverallRating
if (this.getField("TotalRatingLC").value == 0) {
event.value = this.getField("TotalRatingUC").value;
} else {
event.value = (this.getField("TotalRatingUC").value + this.getField("TotalRatingLC").value) / 2;
}

Changed comparison form comparing a number to a string to comparing two numbers.

Removed unbalanced "(" and change smart quotation marks to dumb quotation marks.

Changed calculation from adding UC to LC divided by 2 to dividing the sum of UC and LC by 2.

If LC and UC fields are calculated you might have an issue with the calculation order of the fields.

The JavaScript console told you the line number in the script and the character count in where it determined an error, in this case a missing ending ")".

There are many free references and tutorials about using Acrobat JavaScript.