Skip to main content
Participant
May 30, 2025
Question

Help with Drop down list fields and sum fields

  • May 30, 2025
  • 1 reply
  • 192 views

Hello!  I am creating a form with a summary page and then detail pages for each quarter.  I am trying to calculate a sum on the summary page that will show the total amount from the detail page based on the drop-down list selection.  I have a total of 35 rows on each of the detail list pages. Each row contains the same dropdown list and a total field that calculates the unit cost x quantity (which is manually entered).  I need a total sum amount for each item in my drop down list.  I have tried the following javascript but it is not working.  Any suggestions or help?

var total = 0;
for (var i=1; i<=35; i++) {
if (this.getField("1stQtrComponentRow"+i).valueAsString=="Food")
total+=Number(this.getField("1stQtrTotalRow"+i).valueAsString);
}
event.value = total;

1 reply

try67
Community Expert
Community Expert
May 30, 2025

You have some problems with the names of some of the fields. Try this code to locate them:

 

var total = 0;
for (var i=1; i<=35; i++) {
	var fname = "1stQtrComponentRow"+i;
	var f = this.getField(fname);
	if (f==null) {
		console.println("Error! Can't find: " + fname);
		break;
	}
	if (f.valueAsString=="Food") 
		total+=Number(this.getField("1stQtrTotalRow"+i).valueAsString);
}
event.value = total;
Participant
May 30, 2025

Thank you so much!  That was very helpful and worked great!