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

Timesheet - Calculate the total Count from multiple Drop down selections

New Here ,
Jun 12, 2025 Jun 12, 2025

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! 

TOPICS
How to
421
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 13, 2025 Jun 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.

View solution in original post

Translate
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 ,
Jun 13, 2025 Jun 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.

Translate
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
New Here ,
Jun 13, 2025 Jun 13, 2025
LATEST

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!

Translate
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