I am having table with two td values
<td><?php echo $row['remun'];?></td>
<td><?php echo $row['lum'];?></td>
it return some values based on row value
for example
Ist column 2nd column
100 150
200 150
300 150
<input type="text" name="grand_total" id="grand_total" />
javascript
<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.
But you can easily manage it from your php loop as well as. definitely, you are using for loop to printing record in table.
<?php
$grand_total=0;
foreach($a as $row){
$grand_total=$grand_total+$row['remun']+$row['lum'];
?>
<td class="remun"><?php echo $row['remun'];?></td>
<td class="lum"><?php echo $row['lum'];?></td>
<?php }?>
<td class="total"><?php echo $grand_total;?></td>
But if you want to do it with js then please follow the below once. Please add some class in your like below.
<td class="remun"><?php echo $row['remun'];?></td>
<td class="lum"><?php echo $row['lum'];?></td>
Now user below jquery code for the Sum of both.
var t1=0;
var t2=0;
var t3=0;
$('.remun').each(function(){
t1=t1+parseInt($(this).html());
});
$('.lum').each(function(){
t2=t2+parseInt($(this).html());
});
t3=t1+t2;
alert(t3);