Calculation Script for Certain Conditions
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Be aware that JS is case-sensitive, so "english" will not match to "English"!

