Copy link to clipboard
Copied
I am creating an expense reimbursement form. I was able to have the form calculate the sum of the expenses added to multiple boxes, but I would like it to then calculate the total of those boxes based on a corresponding check box. The check box would be used for managers to mark the expense as approved. They may wish to approve some but not all expenses so the total could be different from the total added by the employee. The amounts put into the boxes would very every time so I can just assign a value to the check box. Also, I would like the total to cap out at $150 as that is the max reimbursement amount allowed. I have basically no experience with Java script, but I am assuming that’s what I need to make this work?
Copy link to clipboard
Copied
If your fields are named in sequence (Text1-Text5 and checkbox1-checkbox5) you change field names to your actual names since you didn't provide those I used above ones as sample, as 'custom calculation script' of "Total Approved" field try this:
var i, total = 0;
for( i=1; i<=5; i++){
if(this.getField("checkbox"+i).valueAsString != "Off" && typeof this.getField("Text"+i).value === "number")
total += this.getField("Text"+i).value;}
if(total > 150)
event.value = 150;
else event.value = total;
Copy link to clipboard
Copied
If your fields are named in sequence (Text1-Text5 and checkbox1-checkbox5) you change field names to your actual names since you didn't provide those I used above ones as sample, as 'custom calculation script' of "Total Approved" field try this:
var i, total = 0;
for( i=1; i<=5; i++){
if(this.getField("checkbox"+i).valueAsString != "Off" && typeof this.getField("Text"+i).value === "number")
total += this.getField("Text"+i).value;}
if(total > 150)
event.value = 150;
else event.value = total;
Copy link to clipboard
Copied
Hi, thank you for helping. the amount Boxes are labeled as "amount1" and so on (1-5) and check boxes are labeled as "Check Box1" and so on (1-5). I’m sorry if this is a very rudimentary question but I am copying and pasting the script below? I am also unsure of where to place the script. does it go with the Total Approved box?
var i, total = 0;
for( i=1; i<=5; i++){
if(this.getField("checkbox1"+i).valueAsString != "Off" && typeof this.getField("Amount1"+i).value === "number")
total += this.getField("Amount1"+i).value;}
if(total > 150)
event.value = 150;
else event.value = total;
Copy link to clipboard
Copied
Yes, script goes to Total Approved" field as ' custom calculation script'.
You didn't change to correct field names, you said that fields are labeled "Amount1" and in script you changed to "amount1" same for checkboxes? In script you don't need number next to field name, try like this and check that field names are correct:
var i, total = 0;
for( i=1; i<=5; i++){
if(this.getField("Check Box"+i).valueAsString != "Off" && typeof this.getField("Amount"+i).value === "number")
total += this.getField("Amount"+i).value;}
if(total > 150)
event.value = 150;
else event.value = total;
Copy link to clipboard
Copied
Hi, I double checked all the field names, and they are correct, but it still doesn't work. when I check a check box the total approved stays $0. Is there anything else I should check?
Copy link to clipboard
Copied
Can you share your file here?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your last checkbox field is named "CheckBox6" it should be "CheckBox5".
Copy link to clipboard
Copied
Thank you so much!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more