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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:40:07+00:00 2026-06-14T15:40:07+00:00

Im trying to perform simple calculations using jQuery but I’m getting NaN as result.

  • 0

Im trying to perform simple calculations using jQuery but I’m getting NaN as result.

Here is my javascript:

$(document).on('click','.button-group button:not(.done)', function(e){
        e.preventDefault();
        $(this).addClass('active');
        var votevalue = $(this).data('votevalue');
        var image_id = $('.mainimage').data('image_id');
        var votes = $('.mainimage').data('numvotes');
        var totalscore = $('.mainimage').data('totalscore');
            $.ajax({
                type: 'POST',
                url: '?a=vote',
                data: {
                    "votevalue" : votevalue,
                    "image_id" : image_id
                },
                success: function(){
                    var votes = parseInt(votes);
                    votes++;
                    var average = ((parseInt(totalscore) + parseInt(votevalue)) / votes);
                    $('#vote-incremenet').html(votes);
                    $('#display-average').html(average);
                    $('#display-average').show();
                    $('.button-group button').addClass('done');
                }
        }); // end ajax
}); // end click

What am I doing wrong?

  • 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-06-14T15:40:08+00:00Added an answer on June 14, 2026 at 3:40 pm

    When you use parseInt, be sure to pass (parseInt(str), radix)to prevent an automatic conversion to some other base.

    If the input string begins with “0x” or “0X”, radix is 16
    (hexadecimal).

    If the input string begins with “0”, radix is eight
    (octal). This feature is non-standard, and some implementations
    deliberately do not support it (instead using the radix 10).

    For this
    reason always specify a radix when using parseInt.

    (MDN)

    In your case, parseInt(varname, 10);


    If the issue persists, it is likely you are passing an incorrect value to one of the variables you are using for calculation.


    EDIT:

    var votes = parseInt(votes); inside the call-back makes it a local variable. Hence,it has lost the value it was given outside. Do not redeclare it within the callback.

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

Sidebar

Related Questions

I'm trying to perform a simple html request using jquery with the code below.
I'm trying to perform a simple animation using Cocoa. One button causes an image
I am using JDK 7 and I am trying to perform a simple write-to-file
Trying to perform a very simple task here. I have an <ol> that contains
I'm trying to perform a really simple summation in MATLAB. Here is my code:
I am trying to perform a simple query, but Datamapper does not seem to
I'm trying to perform some super simple parsing o log files, so I'm using
I'm trying to perform a simple insertion sort in C# but I don't know
I am trying to perform a simple JQuery AJAX page load within a CodeIgniter
I'm trying to perform a simple replace(); method in JavaScript where I'd like to

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.