Copy link to clipboard
Copied
Hi everyone, I am in the Marine Corps and am in charge of Toys for Tots this year. I need assistance with make a Toys for Tots family application fillable form using Adobe Acrobat Pro 2017. I am very new to Adobe JavaScripts and a "Boot" at software codes period! I want to make it user friendly for the public to use. If some one can help me, you'll actually be help +200k potential families. I am looking to calculate totals with set conditions from 10 dropdown boxes labeled "Gender1 - 10") with "Boy" or "Girl" option, and 10 text field boxes labeled "Age" with 0 - 14 years old (Vague illustration below):
Gender1: Boy Age1: 2
Gender2: Boy Age2: 4
Gender3: Girl Age3: 8
Totals:
Ages| 0 - 4 5 - 9 10 - 14
Boys: 2 0 0
Girls: 0 1 0
Copy link to clipboard
Copied
What are the names of the Total fields?
Copy link to clipboard
Copied
Let's say they are called BoysTotal1, BoysTotal2, BoysTotal1, and the same for girls (GirlsTotal1, etc.).
You can then use this code as the custom calculation script of one of those fields (such as BoysTotal1, for example):
var boys = [0, 0, 0];
var girls = [0, 0, 0];
for (var i=1; i<=3; i++) {
var gender = this.getField("Gender"+i).valueAsString;
var age = this.getField("Age"+i).valueAsString;
if (gender=="" || age=="") continue;
age = Number(age);
if (gender=="Boy") {
if (age<=4) boys[0]++;
else if (age<=9) boys[1]++;
else if (age<=14) boys[2]++;
} else if (gender=="Girl") {
if (age<=4) girls[0]++;
else if (age<=9) girls[1]++;
else if (age<=14) girls[2]++;
}
}
for (var i=0; i<boys.length; i++) {
this.getField("BoysTotal"+(i+1)).value = boys[i];
}
for (var i=0; i<girls.length; i++) {
this.getField("GirlsTotal"+(i+1)).value = girls[i];
}
Edit: Small mistake fixed in the code
Copy link to clipboard
Copied
Ok. I'll try it out and let you know. Thank you for the support thus far?
Copy link to clipboard
Copied
You're welcome?
Copy link to clipboard
Copied
Sorry I meant for ! Instead of ? 😂