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

Calculation Script for Certain Conditions

New Here ,
Feb 27, 2023 Feb 27, 2023

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?

 

 

TOPICS
JavaScript

Views

678

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 ,
Feb 27, 2023 Feb 27, 2023

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;

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 ,
Feb 27, 2023 Feb 27, 2023

Copy link to clipboard

Copied

LATEST

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

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