Update: Final Fix:
$('.gasamount').sum();
var num = $(this).attr("id").replace(/[A-Za-z$,-]/g, "");
$('#gasmoney'+num).val(<cfoutput>#mileage#</cfoutput> * $(this).val());
$('.gasmoney').sum();
What I've been trying to accomplish:
- Create a set value for a row of cells.
- Multiply the user's value by a stored amount.
- Get that result and display the value in the cell directly below it in the next row.
I can't seem to get this to work. Every time I think I'm close I'm returning objects or an undefined value.
Javascript
$('.calc').change(function(){
var classArray = $(this).attr('class').split(' ');
$.each(classArray, function(){
var totalsum = $('.'+this).sum();
$('.ttl'+this).val(Number(totalsum).toFixed(2));
var gas = $('.gasamount4');
var gasAmt = gas.val() * <cfoutput>#mileage#</cfoutput>;
var gasTot = $('gasmoney4').val(gasAmt);
gasTot;
alert(gasTot);
});
//Finding the grandtotal
var grandTotal = $('.row26').parent().children('td:last').children( 'input');
var sum = $('.row25').parent().children('td').children('.calc').sum();
grandTotal.val(Number(sum).toFixed(2));
});
ColdFusion / HTML
<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 <cfif labels[r] EQ "Personal Car: Mileage ##">gasamount#i# </cfif> <cfif labels[r] EQ "Personal Car: Mileage $">gasmoney#i# </cfif><cfif labels[r] EQ "Daily Totals">ttlC#i#<cfelse>R#r# C#i#</cfif><cfif labels[r] EQ "Grand Total">gTtl#r#</cfif>" <cfif labels[r] EQ "Daily Totals" OR labels[r] EQ "Personal Car: Mileage $">readonly="readonly"</cfif> /></cfif></cfif></td>
</cfloop>
<td class="totals"><cfif r EQ 1>Total<cfelse><input type="text" class="ttlR#r#" readonly="readonly" /></cfif></td>
</tr>
</cfloop>
If something wasn't made clear, just ask and I'll do my best to provide any additional information. Thanks.