views:

244

answers:

1

I've got a fairly large table that needs to have a total on the right side and bottom for daily totals.

I've been able to get the side to total correctly, but not the bottom.

I may be thinking too little of this, but currently I have this: (Yes, I know it's not correct and doesn't work. I was testing)

script:

HorizVertiCalc = function(h, v){
  $('.R'+r).sum("keyup", ".vttl"+v);

  $('.C'+v).sum("keyup", ".vtotal"+r+v);
}

markup:

<cfloop from="1" to="#ArrayLen(labels)#" index="r">
  <tr>
    <td class="labels"><cfif ArrayIsDefined(labels,r) AND labels[r] NEQ "Open">#labels[r]#</cfif></td>
    <cfloop from="1" to="7" index="i">
      <td id="Day#i#" class="row#r# col#i#">
        <cfif r EQ 1>#Left(DayOfWeekAsString(i),3)#<cfelse><cfif r EQ 2><input type="text" class="date-mask" /><cfelse><input type="text" class="calc R#r# C#i# vtotal#r##i#" onkeypress="return HorizVertiCalc(#r#, #i#)" /></cfif></cfif></td>
    </cfloop>
    <td class="totals"><cfif r EQ 1>Total<cfelse><input type="text" class="ttl#r# vttl#i#" readonly="readonly" /></cfif></td>
  </tr>
</cfloop>

As you can see, I'm producing the table with loops, and so I need to get the total for each column and each row.

+1  A: 

Does it work if you change line

function(h, v)

to say

function(r, v)

since you are referring to r for the row, not h?

Otherwise, more basically I don't see how $('.R'+r) for instance ever would work, where in here would you end up with anything that has a class .R# ? Granted, I don't know coldfusion

larson4
No. the r and v are javascript identifiers of the variable being passed when the function is triggered. so h - represents #r# (which is an index of a variable. in php it would be $r, if you're more familiar with that language.) hope this helped.
Michael Stone
But, in the codeorizVertiCalc = function(h, v){ $('.R'+r).sum("keyup", ".vttl"+v); $('.C'+v).sum("keyup", ".vtotal"+r+v);}where does the 'r' variable come from?
larson4
ferocious's observation makes sense to me. `HorizVertiCalc` has an argument, `h`, which you don't use. And `r` will be undefined. You have a **ColdFusion** variable `r`, but I don't see where you're declaring a Javascript variable, `r`.
Patrick McElhaney
I had the wrong classes on the input box because I doing rapid testing and forgot to change back. That would explain it. .R is the class name and I'm appending the variable to the end of it. I think that part makes sense now.
Michael Stone