Hi all,
This is driving me nuts. The following validation and recalc routine works fine in Firefox and Safari. But IE6 and IE7 - nothing happens. I can't even get IE to tell me an error message. I can only get a slight guess that it's because I am using DOM, but I thought IE has the DOM model in place.
Help!
<script type="text/javascript">
function recalc() {
var frm = document.forms[0];
for (i=0; i <frm.elements.length; i++){
if (frm.elements.type=="text" && frm.elements.id.match("Quant")!==null && (frm.elements.value=="" || isNaN(frm.elements.value))){
alert ("Must enter numeric quantities (ex. enter 1 instead of one)");
return false;
}
}
//recalc
var total=0;
var row_count;
var quant;
var price;
var clls;
var txt;
var txt2;
var tbl=document.getElementById("myTable");
row_count = tbl.rows.length;
for (i=1;i<row_count-2; i++){
clls = tbl.rows.cells;
txt = clls[0].getElementsByTagName('input')[0];
txt2 = clls[3].getElementsByTagName('input')[0];
if (txt.type=="text" && txt.id!=="txtPromoCode"){ // && txt.id.match("Quant")!==Null){
quant = Math.abs(Math.round(txt.value));
price = Math.abs(txt2.value);
txt.value=quant;
amt=(quant * price).toFixed(2);
clls[4].innerHTML=amt;
total = (total + (quant * price));
}
}
frm.elements["GrandTotal"].value=total.toFixed(2);
return true;
}
</script>
If you wish to see this in action go to Add a couple of lampes to the cart (just click the add to cart icon below an item). Then on the menu on the left, click View Cart. Try to recalc or enter a letter, etc.
This is driving me nuts. The following validation and recalc routine works fine in Firefox and Safari. But IE6 and IE7 - nothing happens. I can't even get IE to tell me an error message. I can only get a slight guess that it's because I am using DOM, but I thought IE has the DOM model in place.
Help!
<script type="text/javascript">
function recalc() {
var frm = document.forms[0];
for (i=0; i <frm.elements.length; i++){
if (frm.elements.type=="text" && frm.elements.id.match("Quant")!==null && (frm.elements.value=="" || isNaN(frm.elements.value))){
alert ("Must enter numeric quantities (ex. enter 1 instead of one)");
return false;
}
}
//recalc
var total=0;
var row_count;
var quant;
var price;
var clls;
var txt;
var txt2;
var tbl=document.getElementById("myTable");
row_count = tbl.rows.length;
for (i=1;i<row_count-2; i++){
clls = tbl.rows.cells;
txt = clls[0].getElementsByTagName('input')[0];
txt2 = clls[3].getElementsByTagName('input')[0];
if (txt.type=="text" && txt.id!=="txtPromoCode"){ // && txt.id.match("Quant")!==Null){
quant = Math.abs(Math.round(txt.value));
price = Math.abs(txt2.value);
txt.value=quant;
amt=(quant * price).toFixed(2);
clls[4].innerHTML=amt;
total = (total + (quant * price));
}
}
frm.elements["GrandTotal"].value=total.toFixed(2);
return true;
}
</script>
If you wish to see this in action go to Add a couple of lampes to the cart (just click the add to cart icon below an item). Then on the menu on the left, click View Cart. Try to recalc or enter a letter, etc.