garethhall Posted August 5, 2009 Share Posted August 5, 2009 Hello, I have the code below that calculates the totals of the selected / quantity of items in the cart. The code works fine on all browsers but for IE 6, 7 and partially works in 8. I get an Unknown runtime error, line 123, char 4, code 0. I do not understand why its is happening? I have checked and confirmed that variables that I pass to the function is correct! From the debugging that I did it seems that the problem is with outputResult? The error I am getting in IE 8 is a Nan error Total function? Any ideas? function itemTotal(phQuantity,saleOption,eKind,outputResult){ theSubTotal = phQuantity.value * saleOption; theSubTotal = theSubTotal.toFixed(2); // round the subtotal 2 decimal points // check if item has a checkbox if(eKind == "checkbox"){ if(phQuantity.checked){ document.getElementById(outputResult).innerHTML = "$"+theSubTotal; document.getElementById(outputResult+'-hidden').value = theSubTotal; Total(document.frmOrder,"subItem"); }else{ document.getElementById(outputResult).innerHTML = " "; document.getElementById(outputResult+'-hidden').value = null; Total(document.frmOrder,"subItem"); } }else{ if(phQuantity.value >= 1){ document.getElementById(outputResult).innerHTML = "$"+theSubTotal; ERROR HERE ON THIS LINE document.getElementById(outputResult+'-hidden').value = theSubTotal; Total(document.frmOrder,"subItem"); }else{ document. getElementById(outputResult).innerHTML = " "; document.getElementById(outputResult+'-hidden').value = null; Total(document.frmOrder,"subItem"); } } } var TotalValue; function Total(field,fieldClass){ TotalValue = 0; var thisField = field.elements; for (var i = 0; i < thisField.length; i++){ if (thisField[i].className == fieldClass){ if (thisField[i].value.length > 0){ TotalValue += parseInt(thisField[i].value); } } } document.getElementById('frmTotal').innerHTML = "$"+TotalValue.toFixed(2); document.getElementById('frmGst').innerHTML = "$"+(TotalValue*12.5/100).toFixed(2); document.getElementById('frmTotalIncl').innerHTML = "$"+(TotalValue*12.5/100+TotalValue).toFixed(2); } Quote Link to comment Share on other sites More sharing options...
haku Posted August 6, 2009 Share Posted August 6, 2009 My ESP tells me that line 123 is the 42nd line down. Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 17 actually document.getElementById(outputResult).innerHTML = "$"+theSubTotal; ERROR HERE ON THIS LINE but yeah, post the whole code.. or at least the HTML Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 7, 2009 Author Share Posted August 7, 2009 Anyone got any Ideas? Quote Link to comment Share on other sites More sharing options...
haku Posted August 8, 2009 Share Posted August 8, 2009 How are you calling itemResult()? Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 9, 2009 Author Share Posted August 9, 2009 I am sorry itemResult() where is that in my function? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 Have you checked that outputResult has the correct value? Quote Link to comment Share on other sites More sharing options...
haku Posted August 10, 2009 Share Posted August 10, 2009 I am sorry itemResult() where is that in my function? Sorry, typo. Where and how is itemTotal() called? Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 12, 2009 Author Share Posted August 12, 2009 I am sorry itemResult() where is that in my function? Sorry, typo. Where and how is itemTotal() called? Hi that function is called on another php page. There is a lot of code to show if you wanna see the whole thing. That said I think this is what you are looking for <input type="text" name="<? echo $phID ?>qty-<? echo $options['optionID']?>opt" id="<? echo $phID ?>qty" size="2" onkeyup ="itemTotal(this,'<? echo $options['optionPrice']?>','text','<? echo $phID ?>qty-<? echo $options[optionID]?>opt')" /> Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 12, 2009 Author Share Posted August 12, 2009 Ohh one more thing Here is a link to the page with the error http://www.smart-photography.co.nz/clientSideSelectOptions2.php Quote Link to comment Share on other sites More sharing options...
haku Posted August 13, 2009 Share Posted August 13, 2009 Here's your problem. You need to change this: <input type="text" name="<? echo $phID ?>qty-<? echo $options['optionID']?>opt" id="<? echo $phID ?>qty" size="2" onkeyup ="itemTotal(this,'<? echo $options['optionPrice']?>','text','<? echo $phID ?>qty-<? echo $options[optionID]?>opt')" /> to this: <input type="text" name="<? echo $phID ?>qty-<? echo $options['optionID']?>opt" id="<? echo $phID ?>qty" size="2" onkeyup ="itemTotal("id="<?php echo $phID ?>qty",'<? echo $options['optionPrice']?>','text','<? echo $phID ?>qty-<? echo $options[optionID]?>opt')" /> Note that I used <?php and not <?. You shouldn't use short tags, so you should actually make all your short tags into full php tags. Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 13, 2009 Author Share Posted August 13, 2009 Thank of the reply Haku but it doesn't work al all now also there is an syntax error on your code there is " missing. What Are are you taking "this" out? Quote Link to comment Share on other sites More sharing options...
haku Posted August 13, 2009 Share Posted August 13, 2009 Ahh sorry, I was going off memory, and it turns out my memory was wrong. I thought that 'this' was supposed to be the ID that you were using for getElementById() in your javascript function, which will fail. But now that I look back at your original function, that wasn't the reference to the ID. Can you show the HTML output of that code, rather than the PHP? Since it is javascript, the PHP is irrelevant. Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 13, 2009 Author Share Posted August 13, 2009 Sure man this is what the php will output. <input type="text" name="95qty-7opt" id="95qty" size="2" onkeyup ="itemTotal(this,'105.00','text','95qty-7opt')" /> Here is a sample page with the code running http://www.smart-photography.co.nz/clientSideSelectOptions2.php Quote Link to comment Share on other sites More sharing options...
haku Posted August 13, 2009 Share Posted August 13, 2009 Try changing this: document.getElementById(outputResult).innerHTML = ; to this: var displayPrice = document.createTextNode("$" + theSubTotal); document.getElementById(outputResult).appendChild(displayPrice); Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 13, 2009 Author Share Posted August 13, 2009 Thank you very much really but I got it working finally. The solution was 1 declare the theSubTotal variable var theSubTotal; 2 do a parseFloat() theSubTotal = parseFloat(phQuantity.value) * parseFloat(saleOption); Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 13, 2009 Author Share Posted August 13, 2009 Sorry I lied it's not solved But now it works in IE8 not not in 6 or 7 Quote Link to comment Share on other sites More sharing options...
garethhall Posted August 13, 2009 Author Share Posted August 13, 2009 It is working now Just for interest sake the last problem was naming IE 6 and 7 does not like to have "-" in the id field. I took it out and it works now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.