By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Group Totals

P: 5
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
Jul 10 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
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.
Jul 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.