Copy link to clipboard
Copied
We use Adobe Acrobat Pro DC for a form that includes a custom calculation script to calculate averages with an if statement.
We have a section of our form that averages ratings for three area (numeric values). We need to adjust the average if one of the three ratings/areas is marked as zero for not applicable to only then average the other two ratings.
We have attempted to create the custom calcuation script with Javascript as follows:
var A = this.getField("CoreValuesRating").value;
var B = this.getField("InitiativeRating").value;
var C = this.getField("JudgementRating").value;
var D = ((A+B+C)/3);
if(B=0) event.value=((A+C)/2);
else event.value=D
This script works great when all three ratings are completed but is not working if the rating for B is entered as 0.
What am I missing in this script to run correctly?
Thank you!!
Copy link to clipboard
Copied
Use B == 0
not B = 0
Copy link to clipboard
Copied
That was it! Thank you!!
Copy link to clipboard
Copied
I would also recommend changing these lines:
var A = this.getField("CoreValuesRating").value;
var B = this.getField("InitiativeRating").value;
var C = this.getField("JudgementRating").value;
To:
var A = Number(this.getField("CoreValuesRating").value);
var B = Number(this.getField("InitiativeRating").value);
var C = Number(this.getField("JudgementRating").value);