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.


Creating a JavaScript calculations

New Here ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

I have a PDF that I need to be able to take information from "GPAHrs1" which contains an integer, and multiply it by "Grade1" which is a string.  The Strings will be A, B, C, D or F.  I need the string of "Grade1" to be converted into an integer as follows: A=4, B=3, C=2, D=1, F=0 before returning the product of (GPAHrs1* Grade1) to a third field called "QP1".

 

So I am creating a VAR for the input field GPAHrs1, and Grade1 with the if else statement to change the letter to a number, and then multipling the two var and having that product show up in field QP1.

Here is what I have in the field for GPAHrs1: 

var GPA1 = this.getField("GPAHrs1").value

Here is what I have in the field for Grade1:

var qpa = this.getField("Grade1").value;
if (event.value == "A") {
qpa.value = 4;
} else if (event.value == "B") {
qpa.value = 3;
} else if (event.value == "C") {
qpa.value = 2;
} else if (event.value == "D") {
qpa.value = 1;
} else if (event.value == "F") {
qpa.value = 0;

  

Then this is my calulation in field "QP1" where I need the value of that product to 

qpa*GPA1

 

This is my first stab at trying to do this so I may be way off base.  Any help would be greatly appreciated.

 

 

 

 

 

 

 

 

TOPICS
JavaScript

Views

31

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 ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

Change this line:

var qpa = this.getField("Grade1").value;

To:

var qpa = this.getField("Grade1");

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 ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

LATEST

Use this script as 'custom calculation script' of "QP1" field:

var qpa = this.getField("Grade1").value;
var GPA1 = this.getField("GPAHrs1").value
var x = "";
if(qpa == "A")x = 4;
else if(qpa == "B")x = 3;
else if(qpa == "C")x = 2;
else if(qpa == "D")x = 1;
else if(qpa == "F")x = 0;
if(qpa == "")event.value = "";
else event.value = GPA1*x;

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