Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
57
rated 0 times [  62] [ 5]  / answers: 1 / hits: 17099  / 9 Years ago, fri, november 13, 2015, 12:00:00

I am adding values to table like:
Item,Quantity,Price,TotalPrice



Now there are multiple rows: How can i sum TotalPrice of all to get GrandTotal using Jquery.



Code:



$(#Product).append( <tr><td id='clientname'> +ClientName+ </td> <td id='item'>+ItemName+</td> <td id='quantity'>+Quantity+</td> <td id='price'>+Price+</td> <td id='totalprice'>+TotalPrice+</td> <td> <a  onClick='deleteRow(this);'>Delete</a> </td> </tr>);


Its possible when i insert new row data its show grand total in textbox/label,Like:



 function TotalPriceCalc()
{
var lblTotalPrice = document.getElementById('lblTotalPrice');
lblTotalPrice.value = sum;
}

More From » jquery

 Answers
65

After you use class= instead of id= .Cause ID MUST be unique. you need to loop through each row and find totalPrice



$(document).ready(function(){
var TotalValue = 0;
$(#Product tr).each(function(){
TotalValue += parseFloat($(this).find('.totalprice').text());
});
alert(TotalValue);
});


While you tagged Jquery .. This is a Jquery solution so please be sure to include Jquery


[#64403] Wednesday, November 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tierney

Total Points: 45
Total Questions: 101
Total Answers: 94

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
;