OGSan
asked on
Javascript sum currency amounts
I have the following routine that generates a "running total" of checkbox menu items (employee concessions), but it is running into two problems: (1) The first item checked does not appear unless another mouse-click is made on the screen, and (2) even though all amounts are currency, the total will occasionally display a bunch of decimal positions (e.g., 10.59 + 2.25 displays as 12.8300000009).
Here is the little function:
Here is the little function:
function checkTotal() {
document.frmPost.runningTotal.value = '';
var sum = 0;
for (i=0;i<document.frmPost.Concession.length;i++) {
if (document.frmPost.Concession[i].checked) {
sum = Number(Number(sum) + Number(document.frmPost.Concession[i].value));
}
}
document.frmPost.runningTotal.value = '$' + sum;
}
And the field that it is being displayed inside of is defined as:<input name="runningTotal" type="text">
Any insights would be very much appreciated!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome, glad to help.
ASKER