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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:47:12+00:00 2026-05-31T14:47:12+00:00

I’m creating a form to input an invoice with dynamically added rows ( as

  • 0

I’m creating a form to input an invoice with dynamically added rows (as seen in this image)

I’m using jquery 1.6.2 to calculate Line Total, sum all Line Totals, calculate Tax and display Total. The problem that I’m having is that calculating Line Total only works for the first added row. As you can see on the image above, the first row (Item 1), is fine (2*30=60), but the second row (Item 2) shows the same total as the first one (it should be 4*100=400). Here’s the code for this part:

<script type="text/javascript">
var $k = jQuery.noConflict();

$k(function (){
    $k('#item_form').live("keyup", "input[name^=linetotal]", function() {
        var quantity = $k('input[name^=quantity]').val();
        var unitprice = $k('input[name^=unitprice]').val();
        $k('input[name^=linetotal]').val(quantity*unitprice);

        var sum = $k('input[name^=linetotal]').sum();

        $k('#subtotal').val(sum);
        $k('#tax').val(Math.round(sum*10*100)/100);
        $k('#total').val(Math.round((sum+Math.round(sum*10*100)/100)*100)/100);
     });
});
</script>   

Any ideas about what should I try? Thank you all!

  • 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-31T14:47:13+00:00Added an answer on May 31, 2026 at 2:47 pm

    You are using $k(input[name^=quantity]').val(); to grab the quantity/unitprice, but this grabs all quantity/unitprice inputs, and .val() gets the value of the first one.

    You need to get the one on the same line, although it is odd that you are waiting for keyup on the linetotal. Wouldn’t you want keyup on quantity and unitprice?

     $k('input[name^=quantity], input[name^=unitprice]').live("keyup", function() {
            var quantity = parseFloat($k(this).parent().find('input[name^=quantity]').val());
            var unitprice = parseFloat($k(this).parent().find('input[name^=unitprice]').val());
            $k(this).siblings('input[name^=linetotal]').val(quantity*unitprice);
    
            var sum = $k(this).siblings('input[name^=linetotal]').sum();
    
            $k('#subtotal').val(sum);
            $k('#tax').val(Math.round(sum*10*100)/100);
            $k('#total').val(Math.round((sum+Math.round(sum*10*100)/100)*100)/100);
         });
    });
    

    Basic jsfiddle demo: http://jsfiddle.net/jtbowden/YxJCF/

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.