Skip to content
Advertisement

how to perform substraction in Html Table using JQuery

Net MVC and i am facing a issue in this . Please help me in this. I am creating a project in which i am just adding a product and show the total bill amount in the below of the table. I am able to do that but when i am removing the item from the table i want my total bill amount will also change but that this not happening in this.

JavaScript

Now if i remove Pencil from the list my TotalBill will be 36 but it shows 71.

Please help me in this. I really appreciate for this.

JavaScript
JavaScript

Please Help me how to get Total Quantity also.

Advertisement

Answer

According to your code, deleteItem is an anchor therefor it has no value or val but you are looking for it in the deleteItem loop.

My recommendation is to have a single function lets call it calc_total, and just call that function in the bottom of both the delete and add functions. And give your anchor a data attribute with the line total (qty * price).

This will give you a single consistent function for calculating the total.

<a data-line_total="${(parseFloat(price) * parseInt(quantity))}" data-itemId="0" href="#" class="deleteItem">

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement