Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple JavaScript Not Working in IE

    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


    Code:
    <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!';
    }
    //-->
    </script>
    <body onload='checkprice("<%Cart.Total%>")';>
    <span id="message"></span>
    </body>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,602
    Thanks
    78
    Thanked 4,387 Times in 4,352 Posts
    What server side language are you using????
    Code:
    <%Cart.Total%>
    won't do anything in ASP or JSP coding. You would need
    Code:
    <%= 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:
    Code:
        price = price.replace(/^\$|,/g, '');
    try this:
    Code:
        price = Number( price.replace(/[^\d\.]/g, '') );
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by hlcno; 06-24-2012 at 03:56 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •