Group Totals

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarStarCoda
    New Member
    • Jan 2008
    • 5

    Group Totals

    Hello people,

    I'm building an application for our company intranet and need to figure out what loop to use (if any) and how to do write the code. Heres what I have...

    I have 4 fields with a dropdown next to each:
    Meter1 | Drpdwn1
    Meter2 | Drpdwn2
    Meter3 | Drpdwn3
    Meter4 | Drpdwn4

    Each drpdwn has the same values: Group1 through to Group5

    I want to group the totals of each of the text boxes so for example if I have the following:

    Meter1 = 50 | Drpdwn1 = Group2
    Meter2 = 95 | Drpdwn2 = Group2
    Meter3 = 20 | Drpdwn3 = Group3
    Meter4 = 59 | Drpdwn4 = Group1

    then I want to calculate the following.

    Group1 = 59
    Group2 = 145
    Group3 = 20
    Group4 = 0
    Group5 = 0

    Please help.

    Thanks

    J
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You could set five variables or have one array with five values initially set to 0. You just need to check the drop downs. Whatever is selected there determines which variable/array value will be added to. Take the corresponding meter value and add it. It helps to use good naming/ids, e.g. Meter1 and Drpdown1.

    Use a loop for the numbers, so you can access them as "Meter"+i, etc. This would allow you to extend in future if required without changing the JavaScript.

    Comment

    Working...