Skip to main content
Participant
February 27, 2023
Question

Calculation Script for Certain Conditions

  • February 27, 2023
  • 1 reply
  • 1464 views

Hello,

 

I am creating a PDF form to calculate students' credits. I would like to calculate the types of credits automatically, for instance, I have a drop down box that selects the department of the class (English, Math, Social Studies, etc) and then next to it, the amount of credits for that class are input. So for instance, in the field for "total english credits" I would like it to find any drop down box that has "english" as the selection and then total the credits listed in the field next to the drop down. But if the drop down has "Social Studies" as the selection, then it shouldn't add the credits in the next field.

 

Is this possible? Is there a better way to arrange this?

 

 

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
February 27, 2023

Since you didn't share field names, let's say dropdown fields are named "Subject1-9" and credit fields are named "Credit1-9"

you can use this as custom calculation script of total english credit field:

var english = 0;
for(var i=1; i<=9; i++){
if(this.getField("Subject"+i).valueAsString == "english" && this.getField("Credit"+i).valueAsString != "")
english += Number(this.getField("Credit"+i).valueAsString);}
event.value = english;

try67
Community Expert
Community Expert
February 27, 2023

Be aware that JS is case-sensitive, so "english" will not match to "English"!