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

  • Home
  • SEARCH
  • 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 6833815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:01:43+00:00 2026-05-26T23:01:43+00:00

I am quite new with jQuery, the following code is a collage of 2

  • 0

I am quite new with jQuery, the following code is a collage of 2 different codes I found to achieve my objective

I have a table with a an image that when clicked it removes a table row, that is the first part of the below code.

The second part of the script finds the sum of all the table rows

I am trying to make it so that when you remove a row the sum also changes accordingly. So when you remove a table row the amount in that table row will be subtracted from the total. I need the sum to change according to the row you delete

jQuery part that removes the table row

$(document).ready(function(){
        $('table#FeatureMatrix td a.delete').click(function()
        {

            {
                var id = $(this).parent().parent().attr('id');
                var data = 'id=' + id ;
                var parent = $(this).parent().parent();




                       parent.fadeOut('slow', function() 
                                           {$(this).remove();});
                    return false;       
            }



        });

Part of jQuery that calculates the sum of all table rows

$(document).ready(function() {
     //this calculates values automatically 
     calculateSum();

     $(".txt").live("keydown keyup", function() {
        calculateSum();
     });
});
        function calculateSum() {
            var sum = 0;
            //iterate through each textboxes and add the values
            $(".txt").each(function() {
                //add only if the value is number
                if (!isNaN(this.value) && this.value.length != 0) {
                    sum += parseFloat(this.value);

                }
                else if (this.value.length != 0){

               }
            });
            $("#sum").html(sum.toFixed(2));
        }

If somebody wants to see the example page on the web this is the link http://webiceberg.net/Prices.php, you can also view the source of the page if you need more detail on the code.

  • 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-26T23:01:44+00:00Added an answer on May 26, 2026 at 11:01 pm

    You simply need to call calculateSum() when you delete the row (tidied the code up a bit as well!):

    $('table#FeatureMatrix td a.delete').click(function() {
        var id = $(this).parent().parent().attr('id');
        var data = 'id=' + id ;
        var parent = $(this).parent().parent();
    
        parent.fadeOut('slow', function() {
            $(this).remove();
            calculateSum();
        });
    
        return false;                   
    });
    

    Note that it has to be done after the $(this).remove() inside the callback otherwise you will call calculate before actually removing the row.

    If you are concerned about it calling calculateSum directly then fire a custom event and listen for that and then recalculate:

    $('table#FeatureMatrix td a.delete').click(function() {
        var id = $(this).parent().parent().attr('id');
        var data = 'id=' + id ;
        var parent = $(this).parent().parent();
    
        parent.fadeOut('slow', function() {
            $(this).remove();
            $.event.trigger("rowDeleted"); // fire custom event
        });
    
        return false;                   
    });
    

    Then listen for this event:

    $('#sum').bind('rowDeleted', function() {    // listen for custom event
        calculateSum();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I'm quite new to jQuery, but found this bizzare problem just now,
I'm quite new to JS and jQuery. I have a problem accessing the properties
New to jQuery here. I've found several web pages that come close to what
I am quite new to JQuery and I have a question about Dot Navigation...
I have the following code that populates a Drop Down List and auto submits
I'm quite new to jquery and didn't find any help on the following problem.
I am quite new to jQuery, so my apologizes if there's something obvious I
I'm quite new to jQuery, and I've written a simple function to check the
I know this question is quite basic but I am new to JQuery and
The following code used to function without attempting to render a new template with

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.