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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:02:02+00:00 2026-06-15T19:02:02+00:00

I am trying to use jquery to iterate through all ‘.invoice-lines’ and generate a

  • 0

I am trying to use jquery to iterate through all ‘.invoice-lines’ and generate a total by summing up all values in the ‘.amount-input’ div.

AJAX dynamically generates the default values in ‘.amount-input’ which can be manually changed by the user. I have been trying to create a function so that every time new data comes in using AJAX, a call will be made to the function updateTotal(), which iterates through all the non-empty ‘amount-input’ values and recalculates the total. I have been having a really tough time accomplishing this, and I would greatly appreciate any help.

JQuery – This is my jquery so far (pseudo code)

function updateTotal(){
   var total=0;
    for(i=0; i < $('.invoice-line').length; i++){
         if($('.amount-input').eq(i).val() != empty)){
              total += $('.amount-input').eq(i).val();
          }
    }
    $('.total').val("$" + total);
}

Markup

<?
    for(i=0; i < 25; i++){
    echo'   <div class="invoice-line">
                <div class="prod-id-cell"><input type="text" class="prod-id-input"></div>

                <div class="amount-cell"><input class="amount-input" type="text" /></div>
            </div>';
    }
?>
    <div class="total">$0.00</div>
  • 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-15T19:02:03+00:00Added an answer on June 15, 2026 at 7:02 pm

    Shortly after posting, I was able to come up with my own solution as follows:

    function updateTotal(){
        var total=0;
        for(i=0; i < $('.invoice-line').size(); i++){
            currentAmount = Number($('.amount-input').eq(i).val().replace(/[^0-9\.]+/g,""));
            total += currentAmount;
        }
        $('.total-number').text("$" + total.toFixed(2));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Jquery to iterate through an array of textboxes where
I am trying to use JQuery to iterate through a number of <li> objects
I'm trying to use the jQuery $.inArray function to iterate through an array and
I'm trying to use Coffeescrip/jQuery to iterate through every span on a page and
I am trying to use jQuery each() to iterate across a group of checkboxes
Trying to use JQuery to scroll through a ul li list using class next
I am need paint my image. I'm trying use JQuery in here this link:
I'm trying to use jquery to detect when the ENTER key is pressed AND
I am trying to use jQuery with CoffeScript . I was following the instructions
I am trying to use jQuery's bounce effect on a few images. When I

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.