Challenging – Changing Total fields based on dropdown choices

westrat

12-10-2016

I’m hoping I can get some help on a hurdle which I’m having a battle with.

In the attached form, I have 2 parts.

In part 1 the user is expected to enter amounts and identify where is those amounts currently sit: (Chequing, Savings, RSP – chosen by the “Account” column dropdowns)

In part 2, I’m looking to display the total Amounts but based on which account the user has chosen.

So if the user

  • chose “Chequing” for Row 1 and entered $10.00 for the Amount
  • chose “Saving” for Row 2 and entered $20.00 for the Amount
  • chose “RSP” for Row 3 and entered $500.00 for the Amount
  • chose “Savings” for Row 4 and entered $10.00 for the Amount

. . . Part 2 would look like

  • Total Amountin Chequing = $10.00

  • Total Amountin Saving = $30.00

  • Total Amountin RSP = $500.00

. . . but if the user changed the dropdown in Row 1 to RSP then Part 2 would look like:

  • Total Amountin Chequing = $0.00

  • Total Amountin Saving = $30.00

  • Total Amountin RSP = $510.00

I’ve been struggling with the use of variable, as I feel the solution lies with them, however I’m having a frustrating time. That, in addition to being a little unsure where best to place the code.

Any help with this would be greatly appreciated.

Answers (3)

Answers (3)

westrat

13-10-2016

First and foremost, I would like to thank you for your help. The time you put into responding to my issue is much appreciated.  I was hoping to impose at bit more. I’ve tried the code but did not find success. Any chance you could take another look? I attach the form with the coding included.

Again, thank you.

_Bruce_Robertson

MVP

13-10-2016

Hi

You could use something like this JavaScript code in the calculate event of ChequingTotal.

var rows = Part1.resolveNodes("#subform[*]")

for (var i = 0; i < rows.length; i++) {

    var row = rows.item(i);

    var accountType = row.resolveNode("AccountType");

    if (accountType !== null && accountType.rawValue == "0") {

        var amount = row.resolveNode("AccountAmount");

        if (!amount.isNull) {

            total += amount.rawValue;

        }

    }

}

total;

Similar code in SavingsTotal and RSPTotal but with accountType.rawValue == "0" changed to accountType.rawValue == "1" and accountType.rawValue == "2" respectively.

You should make the binding values the same across all rows as Row4 had them as 3,4,5.  The code could be a lot easier if you used a table.  If could also be easier if you were only going to have 4 rows, but I have assumed you might add some more at some time.