How to calculate the final total Jquery inventory form

paypal kob

I have created the simple inventory control system. inventory control consist of Product Code, Product Name, Price, Qty, Amount, delete button. after fill all the fields and click add button it will append on the table row successfully below the inventory form. my problem is after adding price one by one finally I couldn't calculate the final total it didn’t display on the total textbox and if I want to delete the item click delete button item it didn't delete successfully at same time amount shouldn't decrease. I tried above problems many times but I couldn’t solve it. Please, anyone will help me to solve above problem thanks.i have attached the coding so far I what I tried was.

function addproduct() {
    var product = {
        barcode: $("#barcode").val(),
        pname: $("#pname").val(),
        pro_price: $("#pro_price").val(),
        qty: $("#qty").val(),
        total_cost: $("#total_cost").val(),
        button: '<button  type="button" class="btn btn-warning btn-xs")">delete</button>'
    };
    addRow(product);
}

function addRow(product) {
    var $tableB = $('#product_list tbody');
    var $row = $("<tr><td><Button type='button' name = 'record'  class='btn btn-warning btn-xs' name='record' onclick='deleterow()' >Delete</td>"
        +
        "<td>" + product.barcode + "</td><td class=\"price\">" + product.pname + "</td><td>" + product.pro_price + "</td><td>" + product.qty + "</td><td>" + product.total_cost + "</td></tr>");
    $row.data("barcode", product.product_code);
    $row.data("pname", product.product_name);
    $row.data("pro_price", product.price);
    $row.data("qty", product.qty);
    $row.data("total_cost", product.total_cost);

    $row.find('deleterow').click(function(event) {
        deleteRow($(event.currentTarget).parent('tr'));
    });
    $tableB.append($row);
    onRowAdded($row);
}

function deleterow() {
    $(this).parents("tr").remove();
}

function deleteRow(row) {
    $(row).remove();
    onRowRemoved();
}

function updateTotal() {
    var total = $('table tbody tr').toArray().reduce(function(pre, post) {
        return pre + parseFloat($(post).data('total_cost'));
    }, 0);
    $('table tfoot .total').text(total);
}

function onRowAdded(row) {
    updateTotal();
}

function onRowRemoved(roe) {
    updateTotal();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<caption> Add Products  </caption>
<tr>
   <th>Product Code</th>
   <th>Product Name</th>
   <th>Price</th>
   <th>Qty</th>
   <th>Amount</th>
   <th style="width: 40px">Option</th>
</tr>
<tr>
   <form class="card" id="frmProject">
      <td>
         <div>
            <input type="text" class="form-control" placeholder="barcode" id="barcode" name="barcode"  required>
         </div>
      </td>
      <td>
         <label id="pro_name" name="pname" id="pname"></label>
         <input  type="text" class="form-control" placeholder="barcode" id="pname" name="pname" disabled >
      </td>
      <td>
         <input type="text" class="form-control pro_price" id="pro_price" name="pro_price"
            placeholder="price" disabled>
      </td>
      <td>
         <input type="number" class="form-control pro_price" id="qty" name="qty"
            placeholder="qty" min="1" value="1"  required>
      </td>
      <td>
         <input  type="text" class="form-control" placeholder="total_cost" id="total_cost" name="total_cost"  >
      </td>
      <td>
         <button class="btn btn-success" type="button"
            onclick="addproduct()">Add
         </button>
      </td>
   </form>
</tr>
</table>
<table class="table table-bordered" id="product_list">
   <caption> Products</caption>
   <thead>
      <tr>
         <th style="width: 40px">Remove</th>
         <th>Product Code</th>
         <th>Product Name</th>
         <th>Unit price</th>
         <th>Qty</th>
         <th>Amount</th>
      </tr>
   </thead>
   <tbody></tbody>
</table>


<div class="form-group" align="left">
   <label class="form-label">Total</label>
   <input type="text" class="form-control" placeholder="Total" id="total" name="total" size="30px"  required>
</div>

Ruben Sala

I'm not sure but I think you were wrong here:

$('table tfoot .total').text(total);

Because total isn't a class but an id

try this:

$('#total').val(total);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to calculate total of all row in jquery

From Dev

Calculate total additions and subtractions from inventory per user

From Dev

How to calculate % of total in MySQL

From Dev

How to calculate % of total in MySQL

From Dev

Javascript: how to calculate the total

From Dev

jquery calculate total with quantity and steps

From Dev

Jquery to calculate total of table row

From Dev

jquery calculate total amount of bill

From Dev

How to display filled form values of page in final tab in JQuery?

From Dev

How to calculate the total of a sum in JSTL

From Dev

How to calculate "running total" in SQL

From Dev

How to calculate total price in php

From Dev

how to calculate total Sum in Excel

From Dev

How to calculate the total distance traveled?

From Dev

How to Calculate Total Less Duplicates?

From Dev

How to calculate Last column total

From Dev

How to calculate a running total in view?

From Dev

How to calculate total price of order?

From Dev

How to Calculate Bill Total JS

From Dev

MySQL: possible to calculate the total inventory cost based on amount per received order?

From Dev

Using checkboxes as buttons to auto calculate a total in jquery?

From Dev

automatically calculate total value using jQuery

From Dev

Calculate total value in table row, JavaScript jQuery

From Dev

How to calculate two input form fields and put the value in another without submitting the form using jquery?

From Dev

How to calculate two input form fields and put the value in another without submitting the form using jquery with JSF

From Dev

Calculate the total of form immediately without having to check a checkbox

From Dev

jquery focus first form element on tab of final

From Dev

How to calculate total tickets available and total tickets sold using MySQL?

From Dev

How do I calculate the sub total and total in a table in the PHP?

Related Related

  1. 1

    How to calculate total of all row in jquery

  2. 2

    Calculate total additions and subtractions from inventory per user

  3. 3

    How to calculate % of total in MySQL

  4. 4

    How to calculate % of total in MySQL

  5. 5

    Javascript: how to calculate the total

  6. 6

    jquery calculate total with quantity and steps

  7. 7

    Jquery to calculate total of table row

  8. 8

    jquery calculate total amount of bill

  9. 9

    How to display filled form values of page in final tab in JQuery?

  10. 10

    How to calculate the total of a sum in JSTL

  11. 11

    How to calculate "running total" in SQL

  12. 12

    How to calculate total price in php

  13. 13

    how to calculate total Sum in Excel

  14. 14

    How to calculate the total distance traveled?

  15. 15

    How to Calculate Total Less Duplicates?

  16. 16

    How to calculate Last column total

  17. 17

    How to calculate a running total in view?

  18. 18

    How to calculate total price of order?

  19. 19

    How to Calculate Bill Total JS

  20. 20

    MySQL: possible to calculate the total inventory cost based on amount per received order?

  21. 21

    Using checkboxes as buttons to auto calculate a total in jquery?

  22. 22

    automatically calculate total value using jQuery

  23. 23

    Calculate total value in table row, JavaScript jQuery

  24. 24

    How to calculate two input form fields and put the value in another without submitting the form using jquery?

  25. 25

    How to calculate two input form fields and put the value in another without submitting the form using jquery with JSF

  26. 26

    Calculate the total of form immediately without having to check a checkbox

  27. 27

    jquery focus first form element on tab of final

  28. 28

    How to calculate total tickets available and total tickets sold using MySQL?

  29. 29

    How do I calculate the sub total and total in a table in the PHP?

HotTag

Archive