Expand my Community achievements bar.

Make calculation based on drop down choice

Avatar

Level 1

Hello,

I've searched the forums but can't seem to nail down a solution for this. I have a repeating subform on one page and a totals page elsewhere. I want to be able to total the choices from the drop down individually. In other words if someone chooses Entertainment and then enters an Amount I want to be able to sum up all the Amounts for Entertainment on the totals page... Hope I am explaining correctly.

I've used code similar to this on the calculate event of the total field:

var fields = xfa.resolveNodes("Page7.BenefitDetails[*].Amount");

var total = 0;


for (var i=0; i <= fields.length-1; i++)

{

var DescriptionChoice = Page7.BenefitDetails[" + i + "].Description.getDisplayItem(Description.selectedIndex);


if (DescriptionChoice == "E - Entertainment")

total = total + fields.item(i).rawValue;

}

this.rawValue = total;

I seem to not be able to access the drop down choice based on the index of the subform.

Any help would be appreciated..

Thanks!

Ken

2 Replies

Avatar

Level 10

Hi Ken,

The first thing to establish is what language are you using? The syntax suggests JavaScript. There is an example here that goes through how to reference objects in both JavaScript and FormCalc: http://assure.ly/kUP02y.

For example, if you are using JavaScript then you will need to resolve the node for the repeating object:

var DescriptionChoice = xfa.resolveNode("Page7.BenefitDetails[" + i + "].Description").getDisplayItem(Description.selectedIndex);

Here is another example of accessing bound and display values of dropdowns, which might help: http://assure.ly/fYCuQ2.

See how you get on with that for starters,

Niall

Avatar

Level 1

Thanks Niall!


Yes. It is Java Script.


Had to make a few corrections, but it worked...

var fields = xfa.resolveNodes("Page7.BenefitDetails[*].Amount");


var total = 0;


for


(var i=0; i <= fields.length-1; i++)

{

var DescriptionChoice = xfa.resolveNode("Page7.BenefitDetails[" + i + "].Description").rawValue;


//xfa.host.messageBox("the DescriptionChoice is: " + DescriptionChoice);


if (DescriptionChoice == 1)


total = total + fields.item(i).rawValue;

}

this.rawValue = total;

I will check out your info on scripting etc too. I have to get a better understanding of the whole resolveNode thing.

Thanks again,

Ken