Hello, I have a page that has checkboxes with prices of products. When I do OnChange checked or unchecked I update the total of an input field. However, I cannot get the decimals to appear. For example the 1st checkbox is worth $14.25 but when check it only shows $14 in the total input. That is the same for all the checkboxs with values that sum in that "total" input holder.
function checkTotal(){
document.listForm.total.value = '';
var sum = 0;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice[i].checked) {
sum = sum + parseInt(document.listForm.choice[i].value).toFixed(2);
}
}
document.listForm.total.value = sum;
}
I also tried parseFloat().toFixed(2). Here is what the checkboxes and total input look like.
echo '<input type="checkbox" name="choice" value="'.$b['currBalance'].'" onChange="checkTotal();"/>';
echo '<input type="text" id="total" name="total" value="0"/>';
I appreciate any insight.