0
Follow
0
View

How to remove column row values ​from table according to another column with jquery

daizhenbin168 注册会员
2023-01-25 03:48

function sumBalance(){
  var table = document.getElementById("balanceTbl");
  var tbody = table.tBodies[0];
  var tr = table.tBodies[0].rows;
  var totalBal = 0;
  for(i=0; i < tr.length;i++){
    var balance = tbody.rows[i].cells[2].children[0].value;
    totalBal += Number(balance);
  }
  document.getElementById("total").innerHTML = totalBal;
}
sumBalance();

document.querySelectorAll("input[name=balance]").forEach(function(balanceElem,pos){
  balanceElem.addEventListener("input",function(){
    sumBalance();
  })
})
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}
Start End balance Trail Id
01/11/2022 01/15/2022 high stretch 2
01/11/2022 01/15/2022 low stretch 2
01/25/2022 01/30/2022 high stretch 4
01/25/2022 01/30/2022 inert stretch 4
01/25/2022 01/30/2022 low stretch 4
Total

Don't use id, because in HTML id should be unique between each element, Instead of ID use either name or class. Try to change the balance and see the total. Hope this sample will help. Thanks

About the Author

Question Info

Publish Time
2023-01-25 03:48
Update Time
2023-01-25 03:48

Related Question