4 Replies Latest reply on Nov 15, 2017 6:36 AM by anom10583639

# PDF if, then statement: need help please!

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.

• ###### 1. Re: PDF if, then statement: need help please!

You need to remove unbalanced parenthesis.

• ###### 2. Re: PDF if, then statement: need help please!

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

• ###### 3. Re: PDF if, then statement: need help please!

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.