• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to sum all td values ?

#1
Code:
<td><?php echo $row['remun'];?></td>
 <td><?php echo $row['lum'];?></td>

Code:
for example
Ist column   2nd column
100              150
200              150
300              150
Code:
<input type="text"  name="grand_total" id="grand_total" />
Code:
<script>    
 $('#dynamic-table tr').each(function() {
  if (!this.rowIndex) return; // skip first row
  var customerId = this.cells[4].innerHTML;
  alert(customerId);
 $("#grand_total").val(customerId);
});
i get only first row value but i want sum of all fields.
Reply

#2
That's because you are assigning individual value to the field, not sum. Haven't tested it, but something like this should work:

Code:
<script>
function updateTotal()
{
    var total = 0;
    $('#dynamic-table tr').each(function() {
        if (!this.rowIndex) return; // skip first row
        var customerId = this.cells[4].innerHTML;
        total += customerId;
    }
    $("#grand_total").val(total);
});

Out of curiosity, why are you not doing that on PHP side?
Reply

#3
@kvanaraj,

Why don't you let the database do the heavy lifting and just send the final values and total to the view?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.