View Full Version : Simple JavaScript Not Working in IE

06-24-2012, 12:51 AM
Hi all,

I have this simple script that calculates a customers current cart total and shows when they are eligible for free shipping.

For some reason it won't work in old versions of IE. I did some googling and some people say onload doesn't work in IE but I can't find an alternative method.

Any help would be great, thanks1

<script language=JavaScript>
function checkprice(price) {
var freeprice = 99;
price = price.replace(/^\$|,/g, '');
if(price >= freeprice) document.getElementById('message').innerHTML = 'Congratulations! Shipping is free!';
else document.getElementById('message').innerHTML = 'You are only $' + (freeprice - price).toFixed(2) + ' away from being eligible for free shipping!';
<body onload='checkprice("<%Cart.Total%>")';>
<span id="message"></span>

Old Pedant
06-24-2012, 03:23 AM
What server side language are you using????


won't do anything in ASP or JSP coding. You would need

<%= Cart.Total%>

And given that you are getting the Cart.Total from server-side code, why wouldn't you do that calculation and the display of the message from server-side code???

Anyway, I don't see anything in there that would prevent it from working with IE.

I see a mistake that would affect *ALL* browsers, though. You are comparing a string (price) to a number (freeprice) and depending on what is in price that might not work at all.

In place of this line:

price = price.replace(/^\$|,/g, '');

try this:

price = Number( price.replace(/[^\d\.]/g, '') );

06-24-2012, 04:51 AM
First off thanks so much for taking the time to look at this.

It's crappy network solutions ecommerce platform. <%Cart.Total%> is there markup you throw anywhere to render the current cart total. So you can insert it somewhere you need.. in this case this javascript.

I did what you said and changed that line but it's still not showing up in IE 9 when in computability mode.

So that's why I believe it's something to do with document.write or something else where IE8 or lower doesn't know what to do with it and doesn't render the line of code.

You can test this local by replacing the markups with any number just as a test.

Again thanks so much for taking your time. I really appreciate it. It's been something I've been trying to figure out for awhile and it just seems stupid.

Just FYI. It's a platform that I don't have access to the code base.