Skip to main content
Participant
June 12, 2025
Answered

Timesheet - Calculate the total Count from multiple Drop down selections

  • June 12, 2025
  • 1 reply
  • 385 views

Good day

 

Can anyone assist on a calculation scrip to count the drop down selection based on following options: "On" Off" "Travel".

I have 31 rows each with the drop down selection options. 

At the bottom of my form, I've added a section to provide the user with a count of each. 

 

Tried multiple calculations but wont work. please help!

Thank you! 

Correct answer try67

Here's the calculation code for the total field for "On": 

 

var total = 0;
for (var i=1; i<=31; i++) {
	var fname = "Drop down#"+i;
	var f = this.getField(fname);
	if (f==null) {
		console.println("Error! Can't locate the field: " + fname);
		continue;
	}
	if (f.valueAsString=="On") total++;
}
event.value = total;

 

You can easily adjust it for the others. Just change the value in quotes in this line:

if (f.valueAsString=="On")

 

Make sure you fix the errors you have in the other calculation scripts, though!

Also, I would recommend setting the option for all the drop-downs to commit their selected values immediately (under Properties, Options). Otherwise, the calculation will only update once the user exits the drop-down field, instead of when they make a selection in it.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 13, 2025

Here's the calculation code for the total field for "On": 

 

var total = 0;
for (var i=1; i<=31; i++) {
	var fname = "Drop down#"+i;
	var f = this.getField(fname);
	if (f==null) {
		console.println("Error! Can't locate the field: " + fname);
		continue;
	}
	if (f.valueAsString=="On") total++;
}
event.value = total;

 

You can easily adjust it for the others. Just change the value in quotes in this line:

if (f.valueAsString=="On")

 

Make sure you fix the errors you have in the other calculation scripts, though!

Also, I would recommend setting the option for all the drop-downs to commit their selected values immediately (under Properties, Options). Otherwise, the calculation will only update once the user exits the drop-down field, instead of when they make a selection in it.

Participant
June 13, 2025

Thank you so much! It worked like magic!

I really wish there for there was a compendium t of scipt calculations for lamen Adobe Acrobat form creators!

Have a super day!