Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6163133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:46:24+00:00 2026-05-23T21:46:24+00:00

Hello i have created a javascript function that recaculates the grand total of an

  • 0

Hello i have created a javascript function that recaculates the grand total of an order when the delivery method is changed. The code works fine in firefox, chrome and i.e 9 but returns NAN in i.e 8 and 7, which i understand means Not a number.

I have tried using parseInt, pareseFloat and Number but can’t understand why it does not work in i.e 6, 7 or 8

my code is as follows

<script type="text/javascript">
function ChangePrice(a)
{
    // grabs the delivery price of the selected option i.e 10.99
    var price = parseFloat(a);

    // grab delivery price which is currently on screen i.e 4.99
    old_price = document.getElementById('delivery-sidebar').innerHTML;
    // removing the span tags around the function which are not needed
    old_price = old_price.replace('<SPAN class=price>','');
    old_price = old_price.replace('</SPAN>','');


    //grab subtotal price (which does not include delivery) which is currently on screen  i.e 34.99    
    var subtotal = document.getElementById('overall').innerHTML;
     // removing the span tags around the function which are not needed
    subtotal = subtotal.replace('<span class="price">','');
    subtotal = subtotal.replace('</span>','');
    subtotal = subtotal.replace('£','');

    // converting subtotal to float 
    subtotal=parseFloat(subtotal);

    // if the price of the delivery does not match the price currently on screen
    if (price != old_price)
        {
      //add new price against subtotal 
      var overall_total = (parseFloat(subtotal))+(parseFloat(price));
            // round result to two decimal places i.e 10.99
            overall_total=roundNumber(overall_total,2);
            // update values on screen 
            document.getElementById('delivery-sidebar').innerHTML = '<span class="price">£'+price.toFixed(2)+'</span>';
            document.getElementById('grand-price').innerHTML = '<span class="price">£'+overall_total.toFixed(2)+'</span>';
        }
}
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

</script>

and the markup

    <ul>
      <li>
         <input name="shipping_method" value="tablerate_bestway" id="s_method_tablerate_bestway" checked="checked" class="radio validation-passed" onclick="ChangePrice('0')" type="radio">

<label for="s_method_tablerate_bestway">UK Delivery (3 - 7 Working Days) </label>         
<span class="price">Free delivery</span>                                                
     </li>
    </ul>
    <dd>
      <ul>
          <li>
            <input name="shipping_method" value="flatrate_flatrate" id="s_method_flatrate_flatrate" class="radio validation-passed" onclick="ChangePrice('10')" type="radio">
             <label for="s_method_flatrate_flatrate">Next Day - Orders Before 2pm </label>
             <span class="price"><span class="price">£10.00</span></span>                                                
             </li>
     </ul>
   </dd>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:46:25+00:00Added an answer on May 23, 2026 at 9:46 pm

    You can never rely on reading back the same HTML that the page was created with.

    If you read back <SPAN class="price"> in IE you will actually get <SPAN class=price> (sans ") so your replace fails and the parse to a numeric returns NaN.

    You can either choose to rely on .replace('<SPAN class=price>','i') or better give the span an id: <SPAN id="totalprice" class="price">£xxx</span> and get the numeric value from its innerHTML, or even better retain all the numeric values in memory in the first place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method in codeigniter that looks like this, public function category() {
i have JavaScript components, that has following architecture: var MyComponent = function(params) { setup(params);
Hello everyone~ I have a problem to solve~ I have created a server that
Let's say we have the following JavaScript/jQuery code below function createElement(i, value) { return
I have a library I created, File mylib.c: #include <mylib.h> int testlib() { printf("Hello,
Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt
I think I have misunderstood how Javascript prototypal inheritance works. Specifically, the prototypes internal
In my test code, I have a simple div that I'm using as a
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello we have an SQL server application running over a low bandwith connection. We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.