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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:23:34+00:00 2026-06-14T08:23:34+00:00

Trying to make a simple form that calculates; the line total, qty total, freight

  • 0

Trying to make a simple form that calculates; the line total, qty total, freight * qty total, then the grand total, have found a bit of code to do the first part in jquery, but not 100% sure how to do the rest!

Below is what I have so far…

Thx
Matt.

<HTML>
    <pre class="prettyprint">
        This is an example of working out total pricing,  original code taken from 
        V3: http://stackoverflow.com/questions/9900369/jquery-calculate-sum-of-fields-dynamic

        -Need to work out total QTY, then multiple total freight by total qty (ie. qty of 5, so 5 x $10 = $50 worth of freight)
    </pre>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <SCRIPT>
        $(function(){
            function doCalc() {
                var total = 0;
                $('tr').each(function() {
                    $(this).find('span.amount').html($('input:eq(0)', this).val() * $('select', this).val());
                });
                $('.amount').each(function() {
                    total += parseInt($(this).text(),10);
                });
                $('div.total_amount').html(total);

            }
            $('button').click(doCalc);
        });
    </script>
    <table class="table table-striped table-condensed table-bordered">
        <thead>
            <tr>
                <th width="20%">Item</th>
                <th width="20%">Unit Price</th>
                <th width="20%">Quantity</th>
                <th width="20%">Total</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Item1</td>
                <td>$10<input type="hidden" value="10"></td>
                <td><select size="1" style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
                    <option value="0" selected>0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select></td>
                <td>$<span class="amount"></span> </td>
            </tr>
            <tr>
                <td>Item2</td>
                <td>$20<input type="hidden" class="really don't care" name="testing" value="20"></td>
                <td><select size="1" class="input-small" name="var_1_1" style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
                    <option value="0" selected>0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select></td>
                <td>$<span class="amount"></span> </td>
            </tr>
            <tr>
              <td colspan="3"><strong>Total  QTY</strong></td>
              <td></td>
              <td><strong><div class="total_qty"></div></strong></td>
          </tr>
          <tr>
              <td colspan="3"><strong>Total  Freight @$15 x QTY</strong></td>
              <td></td>
              <td><strong><div class="total_freight"></div></strong></td>
          </tr>
          <tr>
            <td colspan="3"><strong>Total  cost $</strong></td>
            <td></td>
            <td><strong><div class="total_amount"></div></strong></td>
        </tr>
    </tbody></table>
    <button>Go!</button>
</HTML>
  • 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-14T08:23:35+00:00Added an answer on June 14, 2026 at 8:23 am

    Check it out here,
    http://jsfiddle.net/muthkum/hDdtx/2/

    I modified your JS code,

    $(function(){
        function doCalc() {
            var total = 0;
            var qty = 0;
            $('tr').each(function() {
                $(this).find('span.amount').html($('input:eq(0)', this).val() * $('select', this).val());
            var sel_val = parseInt($('select', this).val(), 10);
            if(!sel_val) sel_val = 0;
            qty = qty + sel_val;
            });
            $('.amount').each(function() {
                total += parseInt($(this).text(),10);
            });
            $('.total_qty').text(qty);    //Total QTY calculation
            $('.total_freight').text(15*qty);   //Total Freight @$15 x QTY calculation
            $('div.total_amount').html(total);  //Total Cost
    
        }
        $('button').click(doCalc);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF form where I'm trying to make a simple input form.
I'm trying to make a simple budget form. What I need is that if
I'm trying to make a simple Windows form app that does things. I'd like
I'm trying to make a simple form that contains textboxes that draw from a
Basically I am trying to make a simple form that allows the user to
I am trying to make a simple Windows Form application that will show different
I'm trying to make a simple form, but it's working not so fine. This
Trying to make simple minesweeper game in python, but have one problem. I have
I'm trying to make a list view in a page that is liked form
I'm trying to make a simple login script that will check the inputted username

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.