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 1003595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:00:16+00:00 2026-05-16T08:00:16+00:00

I am experiencing something odd, please see below. Why is alert 1 outputting 0

  • 0

I am experiencing something odd, please see below. Why is alert 1 outputting 0 but alert 2 outputting the correct sum? They are set to the same thing…

var sumTotal = parseFloat($('#tb1').val()) + parseFloat($('#tb2').val());
//tb1.val() == 3, tb2.val() == 5;    

1) alert(sumTotal); //Outputs 0;
2) alert(parseFloat($('#tb1').val()) + parseFloat($('#tb2').val())); //Outputs 8;

Exact code:

    $(document).ready(function () {
        var koh = 1;
        var sumTotal = parseFloat($('#tb1').val()) + parseFloat($('#tb2').val());
        window.setInterval(function () {
            // correct value
            tb3.val(parseFloat($('#tb1').val()) + parseFloat($('#tb2').val())); 
            tb3.val(parseFloat(sumTotal)); // 0
            tb3.val(sumTotal); // 0
            tb3.val(koh++) //increments +1
        }, 2500);
    })

since koh increments +1 can this still be a scoping issue?

  • 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-16T08:00:16+00:00Added an answer on May 16, 2026 at 8:00 am

    sumTotal is calculated before the values of the text boxes have changed. If they default to 0, the result will be 0, and it won’t change even if the text boxes’ values do.

    If they default to blank, sumTotal is NaN — and it still won’t change.

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

Sidebar

Related Questions

I am experiencing a problem with some Javascript - please see my site and
I am experiencing something weird and have a workaround already, but I don't think
I'm experiencing something odd here, that I don't recall ever running into. I'm doing
I'm experiencing something rather odd. I'm tinkering with NHibernate 3.2 mapping by code and
Note: This is not a problem i'm experiencing, but it is something i'd like
we're experiencing repetitive memcache errors. I see a LogAndContinueErrorHandler so requests don't fail but
I am experiencing an odd behaviour from a TreeView control. As you can see,
I'm experiencing something odd with -scrollViewDidScroll: In every call I obtain the last object
I'm experiencing something odd. Whenever I attempt to create a DirectoryInfo object in my
I'm experiencing something that I can't explain with Rails 2.3.2. I've created a new

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.