• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

1.9K

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

Copy link to clipboard

Copied

Use B == 0

not B = 0

 

Votes

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

Votes

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
Community Expert ,
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);

Votes

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