Aronaman
6 months ago

sum ajax

Posted 6 months ago by Aronaman

html

<tbody id="tBody"></tbody>
 <tfoot>
   <tr>
     <th class="text-center" colspan="9">Grand Total Payment Price</th>
     <th id="grand_total"></th>
   </tr>
</tfoot>

ajax

success:function(res){ 
var bodyData = '';
 var i=1;
 var=grandTotal=0;
 $.each(res,function(index,row){ 
bodyData+='<tr id="row_'+rowCount+'" >'
.......
+'<td id="sum_'+row.id+'">'+row.discount_price_on_web+"</td><td>"
...
bodyData+="</tr>";
}

 $("#tBody").append(bodyData);

my question is all the list working fine, but how can i sum the "list discount_price_on_web" and save in html id="grand_total"?

i try this after bodyData+=""

 $("[id*=sum]").each(function(){
    grandTotal=grandTotal+parseFloat($(this).html());
         });
   $("[id*=grand_total]").html(grandTotal.toString());

Not Working !! any help

Please sign in or create an account to participate in this conversation.