PHP JQuery Running Total Problem

Hi All,

I've been helped by a few wonderful people here so far and in my ongoing efforts to learn JQuery, I'm also running up against complex requirements (at least for me).

What I'm trying to do is provide a running total of employee hours by day (column).  You will see in the example code below, I have running total by row (week by employee) and combined total (all employee hours).  However, I'm trying to figure out how to also get a running total for all employees for the day (see screenshot totals, in green, below).

I use the select name, class and later split the value element in the jquery to get the values needed.  My issue is I'm not sure how to do it by day.  I can add the calendar date to the name, class or id but since I'm creating all the dropdowns dynamically, how do I use the calendar date and then call it in the jquery function with in a way which doesn't cause an issue with the functions already created?

Any help/input, as always, is greatly appreciated!  =)

You can see my existing code here:
Example In Green
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Quick code sample to point you in the right direction. Give the table that has all of the selects an id of hours. Add the function below. It will output the selected value of the given day where curDayIndex is the index of the tr. So, to call it for day one, you would call getDayHours(1).

function getDayHours(curDayIndex) {
  var DayTotal = 0;
  $('#hours tr:gt(0)').find('td:eq(' + curDayIndex + ') option:selected').each(function(){console.log($(this).val());});
  return DayTotal;

Open in new window

Calling getDayHours(1) will output 1_8.5 and 10_0 in your example.

What you'll want to do with my sample code is change the console.log to splitting the value of the selects and adding it to DayTotal. Let me know if you need more info.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
@btuskey did my solution help?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.