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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:09:23+00:00 2026-06-17T20:09:23+00:00

I have a table with column totals and row totals. I have it set

  • 0

I have a table with column totals and row totals. I have it set up that when someone enters a number into the input fields it calculates them on keyup and on page load. The columns are recalculating on page load just fine, but the rows are resetting back to zero.

// Calculate Sum Of Rows
$(function() {
    $('input').live('keyup', newSum);
    newSum();
});
function newSum() {
    var sum = 0;
    var thisRow = $(this).closest('tr');
    //iterate through each input and add to sum
    $(thisRow).find("input:not(.ignore):not(.description):not(.miles)").each(function() {
            val = parseFloat(this.value);
            sum += isNaN(val) ? 0 : val;   
    });
    //change value of total
    $(thisRow).find(".sumtotalclaimed").html(sum);
}

Here’s the code for the columns, which works perfectly (recalculates on page load):

// Calculate Sum Of Columns
$(function() {
    $('input.miles').live('keyup', calculateSum1);  
    calculateSum1();
} );
function calculateSum1() {
    var sum = 0;
    //iterate through each textboxes and add the values
    $("input.miles").each(function() {
        //add only if the value is number
        if(!isNaN(this.value) && this.value.length!=0) {
            sum += parseFloat(this.value);
        }
    });
    //.toFixed() method will roundoff the final sum to 2 decimal places
    $("#summiles").html(sum);
}

I thought it would be as simple as putting newSum(); in the function, but that’s not working. Any ideas what I’m doing wrong?

Thanks!

  • 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-17T20:09:24+00:00Added an answer on June 17, 2026 at 8:09 pm

    You have no this on page load. So it can’t find thisRow. The offending line is var thisRow = $(this).closest('tr');

    The way I’ve done this in the past is to find the first input in question and trigger the event, thus calling the method with a fully inflated event.

    For example, instead of calling newSum(); directly, call $('input').first().trigger('keyup') which will automatically call the newSum function.

    EDIT: http://jsfiddle.net/DTPZQ/3/

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

Sidebar

Related Questions

I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
I have a table column where each row has one of three states, and
I have a set of queries that outputs a pivot table. Is it possible
I have a table that has just one row that has columns with class='99999'.(
I have a table user with column data which has most of the fields
I have one datatable. In that table I have columns named [Total Day], [Present
I have a table column I’m trying to expand and hide. jQuery seems to
I have a table column called post_tags within a table called posts where assigned
Imagine I have this table: Column A | Column B | Column C ------------------------------
If I have a table column with data and create an index on this

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.