Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Custom Calculation Script for if then statement

New Here ,
Sep 03, 2021 Sep 03, 2021

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!!

 

TOPICS
How to, JavaScript, PDF forms

Views

44

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Use B == 0

not B = 0

 

Likes

Translate

Translate

Report

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 ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

LATEST

That was it!  Thank you!!

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Sep 03, 2021 Sep 03, 2021

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);

Likes

Translate

Translate

Report

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