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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:55:18+00:00 2026-05-15T08:55:18+00:00

I have the following jQuery script: $(document).ready(function() { $.ajax({ url: ‘temp.ajax.php’, type: ‘GET’, success:

  • 0

I have the following jQuery script:

$(document).ready(function() {
        $.ajax({
            url: 'temp.ajax.php',
            type: 'GET',
            success: function(data){
                $("#total_plus_aditional").val(data);                   
            }
        });

        tempTotal = parseFloat($("#total_plus_aditional").val());

        $("#cost_valoare").change(function(){                   
            var sum = parseFloat(tempTotal) + parseFloat($("#cost_valoare").val());
            $("#total_plus_aditional").val(sum);  
        });
});

Now, here’s what I want to do: the temp.ajax.php returns a float value. First, that float value is assigned to an input field in the html so the user can see the number. Then, if the user enters a number in another input field, I would like to make the sum of those two numbers and rewrite the value in the first input field.

The problem is that if I write a number in a second field, the content of the first field (with the float number returned by ajax call) turns to NaN.

Why is this happening?

P.S. I’m saving the value returned by the ajax call in a separate variable because I would like to have the same value if the user changes his mind and enters another value in the second field after he already entered one.

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

    That line of code that initializes the global variable “tempTotal” almost certainly runs before your AJAX call returns from the server. Thus, it’s a NaN because the field was empty when that ran.

    Put that line of code in the “success” function and see what happens.

    edit — wait — why are you calling parseFloat twice on the same value? Don’t do that. Really, the whole “tempTotal” thing is useless. Just have the “change” handler do this:

    var sum = parseFloat($('#total_plus_aditional').val()) + parseFloat($("#cost_valoare").val());
    

    If you really must save the value, do it in the AJAX response:

            success: function(data){
                $("#total_plus_aditional").val(data);   
                tempTotal = parseFloat(data);                
            }
    

    and then don’t call parseFloat on it again in the “change” handler.

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

Sidebar

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not sure if this will solve your problem but your… May 16, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer Why are you taking SHA1 hash of it? Just do… May 16, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer To be precise, garbage collectors are a problem for real-time… May 16, 2026 at 3:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following Jquery script: $(document).ready(function () { // When the submit button
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have an issue with a jQuery script I wrote that is driving me
I have the following jQuery event that gets fired every time an anchor is
I am using jQuery and Ajax. My MainFile has the following code: <html> <head>
I'm pulling my hair out trying to get a jQuery script working that will
I have the following JQuery, I want to display the default divarea1 visible when
I have the following code and it's working (as usual) in everything but IE.
I have the following code which is loading an xml file to populate a
I have the following code which loads a xml file to populate a dropdown.

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.