how to dynamically add row and calculate sum using jquery

how to dynamically add row and calculate sum using jquery
<html>
<head>
    <title>sum of all textbox each row</title>
    <script src ="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
    <input type="number" class="txtnum" id="txt1"><br/>
    <input type="number" class="txtnum" id="txt2"><br/>
    <input type="text" id="total" disabled />
</body>
<script>
$(document).ready(function(){
    $(".txtnum").each(function(){
        $(this).keyup(function(){
            //var rowid = parseInt($(this).attr('id').split('_').pop());
            var total = 0;
            $(".txtnum").each(function(){
                if (!isNaN(this.value) && this.value.length != 0){
                    total += parseFloat(this.value);
                }
            });
            $('#total').val(total.toFixed(2));
        });
    });
});
</script>
</html> 

Post a Comment

0 Comments