latemodern
09-13-2006, 05:00 PM
Hi,
I'm really new to JS and have just written my first function which calculates total, ex vat, and vat value in an invoice table using the price of the items and the quantity input by the user. This works fine in Firefox but nothing happens in ie6. Any ideas?
function calculateTotal(quantity, row) {
var trs = document.getElementsByTagName("tr");
var tr = trs.length
var tds = trs[row].getElementsByTagName("td");
td = tds.length;
for(var x=0; x < td; x++){
if(tds[x].getAttribute("class") == "price"){
var price = tds[x].firstChild.nodeValue;
var total = quantity * price;
}
if(tds[x].getAttribute("class") =="total"){
tds[x].firstChild.nodeValue = total.toFixed(2);
}
if(tds[x].getAttribute("class") == "exvat"){
var exvat = total/1.175;
tds[x].firstChild.nodeValue = exvat.toFixed(2);
}
if(tds[x].getAttribute("class") == "vat"){
var vat = (total- exvat);
tds[x].firstChild.nodeValue = vat.toFixed(2);
}
}
}
I'm really new to JS and have just written my first function which calculates total, ex vat, and vat value in an invoice table using the price of the items and the quantity input by the user. This works fine in Firefox but nothing happens in ie6. Any ideas?
function calculateTotal(quantity, row) {
var trs = document.getElementsByTagName("tr");
var tr = trs.length
var tds = trs[row].getElementsByTagName("td");
td = tds.length;
for(var x=0; x < td; x++){
if(tds[x].getAttribute("class") == "price"){
var price = tds[x].firstChild.nodeValue;
var total = quantity * price;
}
if(tds[x].getAttribute("class") =="total"){
tds[x].firstChild.nodeValue = total.toFixed(2);
}
if(tds[x].getAttribute("class") == "exvat"){
var exvat = total/1.175;
tds[x].firstChild.nodeValue = exvat.toFixed(2);
}
if(tds[x].getAttribute("class") == "vat"){
var vat = (total- exvat);
tds[x].firstChild.nodeValue = vat.toFixed(2);
}
}
}