While using check box section in asp.net ,grid view,with the following code.
not able to calculate the sum of the amount ,
eg,
-
if the grid row having the value with 1,001,870.00 then,getting the
result as 1 -
if the grid row having the value with 976,000 then,
getting the result as 976,000
am using the following script function,
function GetSelected() {
debugger;
var grid = document.getElementById("<%=grvGroup.ClientID%>");
var checkBoxes = grid.getElementsByTagName("INPUT");
var amountFC = 0;
var amountVAT = 0;
var amountSUMTOT = 0;
var countSelect = 0;
var totalValAmount = 0;
if (grid.rows.length > 0) {
for (var i = 1; i < grid.rows.length; i++) {
var checkBoxes = grid.rows[i].getElementsByTagName('input');
var checkedid = checkBoxes[0].getAttribute('id');
var checkbox = document.getElementById(checkedid);
if (checkbox.checked) {
Amt = grid.rows[i].cells[5].innerText.replace(",", "");
amountFC += parseFloat(Amt);
Amt = grid.rows[i].cells[6].innerText.replace(",", "");
amountVAT += parseFloat(Amt);
countSelect++;
}
}
jQuery('#<%=txtTotalAmount.ClientID %>').val(amountFC);
jQuery('#<%=txtTotalVat.ClientID %>').val(amountVAT);
var totalAmount = parseFloat(jQuery('#<%=txtTotalAmount.ClientID %>').val());
var totalVat = parseFloat(jQuery('#<%=txtTotalVat.ClientID %>').val());
var totalSum = totalAmount + totalVat;
jQuery('#<%=txtPayableAmount.ClientID %>').val(totalSum);
}
if (grid.rows.length - 1 == countSelect) {
document.getElementById("ContentPlaceHolder1_checkallselect").checked = true;
}
else {
document.getElementById("ContentPlaceHolder1_checkallselect").checked = false;
}
}
2
Answers
In the documentation of JS function
replace()
we can read the following:These are the two options you have to remove all
,
from your number.ReplaceAll()
Using REGEX
Docs
Replace
Replace all
Please follow DRY(Don’t Repeat Yourself) principle.
Best to create a polyfill on window object that named i.e. parseFloatFromString().
Put this code on load of your project.
For your case: