I have a table with inputs that are summed vertically and horizontally using JQuery. The bottom row totals the first two columns and is then supposed to sum their totals in <input type="text" name="grand_total" class="numbox_dark" readonly> input. The problem is the <input type="text" name="grand_total" class="numbox_dark" readonly> doesn't update because there is no user interaction with the "total_sales1" and "total_sales2" inputs.
The script I use looks like this:
$(window).load(function(){
$(':input').bind('keypress keydown keyup change',function(){
var $div = $(this).closest('tr');
var postpaid = parseFloat($div.find(':input[name*="_postpaid"]').val(),10),
hup = parseFloat($div.find(':input[name*="_hup"]').val(),10);
if (isNaN(postpaid)) postpaid = 0;
if (isNaN(hup)) hup = 0;
var v = '';
if (!isNaN(postpaid) && !isNaN(hup)){
v = (postpaid + hup);
}
$div.find(':input[name*="_total"]').val(v.toString());
});
});
The table looks like so:
<tr>
<td>Category 1</td>
<td>
<input type="text" name="category1_sales1" class="numbox">
</td>
<td>
<input type="text" name="category1_sales2" class="numbox">
</td>
<td>
<input type="text" name="category1_total" class="numbox_dark" readonly>
</td>
</tr>
<tr>
<td>Category 2</td>
<td>
<input type="text" name="category2_sales1" class="numbox">
</td>
<td>
<input type="text" name="category2_sales2" class="numbox">
</td>
<td>
<input type="text" name="category2_total" class="numbox_dark" readonly>
</td>
</tr>
<tr>
<td><strong>TOTAL</strong></td>
<td>
<input type="text" name="total_sales1" class="numbox_dark" readonly>
</td>
<td>
<input type="text" name="total_sales2" class="numbox_dark" readonly>
</td>
<td>
<input type="text" name="grand_total" class="numbox_dark" readonly>
</td>
</tr>
How do I get "grand_total" to update as entries are made on the top two rows?