Click here to Skip to main content
15,867,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a table which has a checkbox in each row and ​​column name feepayable and a balance column, I want if any checkbox is checked then in that row check if the balance column is 0 then add feepayable to the total , and if not 0 then balance is added.

The addition is ok but I want that if the checkbox is unchecked, subtract value accordingly.

Please help. Thanks in advance.

What I have tried:

JavaScript
$("input[type=checkbox]").click(function(){       
    var chkVal = $(this).val();
     if($("#ReceiptList"+chkVal).is(":checked")){
       var feepayable = parseInt($("#feepayable"+chkVal).html());
       var balance = parseInt($("#balance"+chkVal).html());
       if(balance == 0){
       $("#total").val(parseInt($("#total").val()) + feepayable);
       }
       else
       {
        $("#total").val( parseInt($("#total").val()) + balance);
       }
     }
else if(!($("#ReceiptList"+chkVal).is(":checked"))){
       var feepayable = parseInt($("#feepayable"+chkVal).html());
       var balance = parseInt($("#balance"+chkVal).html());
       if(balance == 0){
       $("#total").val(parseInt($("#total").val()) - feepayable);
       }
       else
       {
        $("#total").val( parseInt($("#total").val()) - balance);
       }
     }
    });
Posted
Updated 19-Jul-22 1:28am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900