Hamza Shah

Hamza Shah

  • NA
  • 87
  • 22.8k

I want Grand Total of the selected products

Oct 26 2020 2:09 AM
I'm selecting the products from dropdown and selected items are appearing in below table. If I'm increasing the quantity of products the subtotal also increasing accordingly. Now I want the Grand Total of selected products. How can i do it?
 
Here's My code
  1. <div class="col-lg-12">  
  2. <table class="table">  
  3. <thead>  
  4. <tr>  
  5. <th scope="col">Product Idth>  
  6. <th scope="col">Companyth>  
  7. <th scope="col">Product Nameth>  
  8. <th scope="col">Price per productth>  
  9. <th scope="col">Quantityth>  
  10. <th scope="col">Sub Totalth>  
  11. </tr>  
  12. </thead>  
  13. <tbody>  
  14. </tbody>  
  15. </table>  
  16. </div>  
  17. <div class="savebutton" >  
  18. <input type="button" id="btnSave" value="Save All"/>  
  19. </div>  
  20. <script>  
  21. $('#productSelect').change(function () {  
  22. var id = $(this).val();  
  23. if (id > 0) {  
  24. $.get("GetProduct", { productId: id }, function (result) {  
  25. console.log(result)  
  26. $("tbody").append("" + result.ProductId + "" + result.CompanyName + "" + result.ProductName + "" + result.ProductPrice + "-"" value="0">0+---x")  
  27. });  
  28. }  
  29. }) function subtract(productId, price) {  
  30. var quantity = $("#" + productId + "").text();  
  31. quantity = --quantity;  
  32. if (quantity > 0) {  
  33. $("#" + productId + "").text(quantity);  
  34. $("#sum" + productId + "").text(quantity * price);  
  35. else {  
  36. $("#" + productId + "").text("0");  
  37. $("#sum" + productId + "").text("---");  
  38. }  
  39. }  
  40. function add(productId, price) {  
  41. var quantity = $("#" + productId + "").text();  
  42. quantity = ++quantity;  
  43. $("#" + productId + "").text(quantity);  
  44. $("#sum" + productId + "").text(quantity * price); }  
  45. </script>  

Answers (2)