automatically calculate total value using jQuery

think_user

I want to calculate sum of the numbers the user has entered automatically.When the user delete one number the sum should auto calculate.How to calculate sum of array values using jquery.Please help me to solve this problem.

$(document).ready(function(){
    $('.form-control').change(function(){
        var total = 0;
        $('.form-control').each(function(){
            if($(this).val() != '')
            {
                totalvalue += parseInt($(this).val());
            }
        });
        $('#totalvalue').html(totalvalue);
    });
})(jQuery);
<h2 style="text-align:center;">INVOICE</h2>        

        <form id='students' method='post' name='students' action='index.php'>
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <tr>
                            <th><input class='check_all' type='checkbox' onclick="select_all()"/></th>
                            <th>S. No</th>
                            <th>Job ID</th>
                            <th>Quantity</th>
                            <th>Price</th>
                            <th>Total Price</th>
                        </tr>
                        <tr>
                            <td><input type='checkbox' class='case'/></td>
                            <td><span id='snum'>1.</span></td>
                            <td><input class="form-control" type='text' id='txt_jobid' name='txt_jobid[]'/></td>
                            <td><input class="form-control" type='text' id='txt_quantity' name='txt_quantity[]'/></td>
                            <td><input class="form-control" type='text' id='txt_price' name='txt_price[]'/></td>
                            <td><input class="form-control" type='text' id='txt_totalprice' name='txt_totalprice[]'/> </td>
                        </tr>
                    </table>
                    <button type="button" class='btn btn-danger delete'>- Delete</button>
                    <button type="button" class='btn btn-success addmore'>+ Add More</button>
                </div>
            </form>     Total: <div id="totalvalue">0</div>        
SUBMIT FORM
        </form>
eisbehr

Sometime you used total and sometimes totalValue. Name the variables the same. And remove the (jQuery) at the end. It's wrong there.

$(function() {
    $('.form-control').change(function() {
        var total = 0;

        $('.form-control').each(function() {
            if( $(this).val() != '' )
                total += parseInt($(this).val());
        });

        $('#totalvalue').html(total);
    });

    // trigger initial calculation if wanted
    .change();
});

Example: https://jsfiddle.net/0zpkow5L/
Initial calculation: https://jsfiddle.net/0zpkow5L/1/

Full working example of your code: https://jsfiddle.net/0zpkow5L/8/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculate total value in table row, JavaScript jQuery

From Dev

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

From Dev

Calculate total using hidden field value instead of checkbox value

From Dev

calculate the total value dict

From Dev

Using $sum to calculate the total value in a object, mongoose/mongodb

From Dev

Calculate subtotal and total price depending on selected options using jquery

From Dev

How to calculate automatically using jQuery base on PHP rows?

From Dev

Calculate automatically in a table using jquery when adding or deleting rows

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

Calculate percentage to total using rowPercents

From Dev

Total value with jquery on table

From Dev

Get order total value using jquery from table

From Dev

How to calculate total of all row in jquery

From Dev

How to calculate the final total Jquery inventory form

From Dev

Using Forms in HTML to calculate total price

From Dev

How to calculate the running total using aggregate

From Dev

Calculate total with price and quantity using Angularjs

From Dev

calculate total events in month using pandas

From Dev

How to calculate total disk space using df?

From Dev

Calculate the total time required using Thread Pool

From Dev

Calculate total of a column using linq in c#

From Dev

Calculate annual total from monthly total using Measure in Power BI

From Dev

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

From Dev

Round off total value with jquery

From Dev

Calculating cart total using jQuery

From Dev

row delete but not removing the corersponding value from the total from the label using jquery

From Dev

Calculate total time for which the value was 1 for a specified time period

Related Related

  1. 1

    Calculate total value in table row, JavaScript jQuery

  2. 2

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

  3. 3

    Calculate total using hidden field value instead of checkbox value

  4. 4

    calculate the total value dict

  5. 5

    Using $sum to calculate the total value in a object, mongoose/mongodb

  6. 6

    Calculate subtotal and total price depending on selected options using jquery

  7. 7

    How to calculate automatically using jQuery base on PHP rows?

  8. 8

    Calculate automatically in a table using jquery when adding or deleting rows

  9. 9

    jquery calculate total with quantity and steps

  10. 10

    Jquery to calculate total of table row

  11. 11

    jquery calculate total amount of bill

  12. 12

    Calculate percentage to total using rowPercents

  13. 13

    Total value with jquery on table

  14. 14

    Get order total value using jquery from table

  15. 15

    How to calculate total of all row in jquery

  16. 16

    How to calculate the final total Jquery inventory form

  17. 17

    Using Forms in HTML to calculate total price

  18. 18

    How to calculate the running total using aggregate

  19. 19

    Calculate total with price and quantity using Angularjs

  20. 20

    calculate total events in month using pandas

  21. 21

    How to calculate total disk space using df?

  22. 22

    Calculate the total time required using Thread Pool

  23. 23

    Calculate total of a column using linq in c#

  24. 24

    Calculate annual total from monthly total using Measure in Power BI

  25. 25

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

  26. 26

    Round off total value with jquery

  27. 27

    Calculating cart total using jQuery

  28. 28

    row delete but not removing the corersponding value from the total from the label using jquery

  29. 29

    Calculate total time for which the value was 1 for a specified time period

HotTag

Archive