View Full Version : Calculation Function Works in Firefox Not in IE
The function below generates a value in Firefox but nothing in Explorer. Any help or insight would be appreciated.
dcp
function calcTotal()
{
var subtotal = document.getElementById('subtotal').firstChild.nodeValue;
var postage = document.forms['frmMultipleSelects'].elements['postage'].value;
document.getElementById('total').firstChild.nodeValue=parseInt(subtotal)+parseInt(postage)+'.00';
//set the value of the hiddden form elements.
document.forms['frmMultipleSelects'].elements['total'].value=document.getElementById('total').firstChild.nodeValue;
}
How your element 'subtotal' looks like?
Subtotal is calculated with the following function, this works in both FF and IE:
function calcSubTotal()
{
//get the last coloumn in table [1]
//var table = document.getElementsByTagName("table")[8];
var table = document.getElementById('orderList');
var nodeList = table.getElementsByTagName("tr");
var row, cell, price, subtotal;
//set the subtotal amount to zero so we get a clean calculation.
document.getElementById('subtotal').firstChild.nodeValue='0.00';
//i needs to be 1 because row 0 is not a form element. It is just the header info
for (var i = 1; i < nodeList.length; i++)
{
row=nodeList[i];
cell=row.getElementsByTagName("td")[4];
price= cell.getElementsByTagName("span")[1].firstChild.nodeValue;
subtotal= parseInt(document.getElementById('subtotal').firstChild.nodeValue)+parseInt(price);
//we at the '.00' to make it look like money syntax. we can do that since everythign ends in .00
document.getElementById('subtotal').firstChild.nodeValue=subtotal+".00";
}
//set the value of the hiddden form elements.
document.forms['frmMultipleSelects'].elements['subtotal'].value=document.getElementById('subtotal').firstChild.nodeValue;
}
I have asked you something else
How your element 'subtotal' looks like?
Anyway, looking at:
document.forms['frmMultipleSelects'].elements['subtotal'].value=document.getElementById('subtotal').firstChild.nodeValue;
I see that you have two elements, one with id='subtotal', one with name='subtotal'. Change one of them (for instance id="subtotalID") to avoid errors
Thanks for the tip. Made modification, which had no effect on calculation.
Subtotal is span: <span id="subtotal">0.00</span>
dcp
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.