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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:36:20+00:00 2026-06-09T01:36:20+00:00

I want to calculate each row’s total price by multiplying individual row’s inputs and

  • 0

I want to calculate each row’s total price by multiplying individual row’s inputs and then finally calculate a grand total by adding all the total values of the Total column using JQuery. I am only getting the first row to display total when I enter values. Any help will be greatly appreciated.

     <script type="text/C#" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
         $(document).ready(function () {
            $(".txtMult").each(function () {
                $(this).keyup(function () {
                    multInputs();
                });
            });
           });

           function multInputs() {
               var mult = 0;
               $(".txtMult").each(function () {
                   var $val1 = $('#val1').val();
                   var $val2 = $('#val2').val();
                   var $total = ($val1 * 1) * ($val2 * 1)
                   $('#multTotal').text($total);
               });
           }

    </script>
    @using (@Html.BeginForm())
    {
        <table>
        <tr>
            <th>
                Quanity
            </th>
            <th>
                Unit Price
            </th>
            <th>
                Total
            </th>
        </tr>
        @for (int i=0; i < 5; i++)
        {

            <tr>
                <td>
                    <input class ="txtMult" name="txtEmmail" id="val1"  />
                </td>
                <td>
                    <input class ="txtMult" name="txtEmmail" id="val2"/>
                </td>
                <td>
                    <span id="multTotal">0.00</span>
                </td>
            </tr>

    }
<tr>
    <td colspan="3" align="right">
        Grand Total# <span id="grandTotal">0.00</span>
    </td>
</tr>
    </table> 
    }

enter image description here

  • 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-09T01:36:22+00:00Added an answer on June 9, 2026 at 1:36 am

    Your html is invalid: the id attribute is supposed to be unique but you are repeating the same three ids in every row. The easiest way to fix this is to change your inputs to have class="val1" and class="val2" instead of id="val1" and `id="val2", and change your row total to have class="multTotal". I’d also move the txtMult class to each of the tr elements with the inputs in them, for ease of selecting those rows:

            <tr class="txtMult">
                <td>
                    <input name="txtEmmail" class="val1"  />
                </td>
                <td>
                    <input name="txtEmmail" class="val2"/>
                </td>
                <td>
                    <span class="multTotal">0.00</span>
                </td>
            </tr>
    

    …and then change the selector in your jQuery code to select by class in the context of the current row. Note also that you don’t need an .each() loop to bind the .keyup() handlers to the elements that match your selector, just use $("someselector").keyup():

     $(document).ready(function () {
           $(".txtMult input").keyup(multInputs);
    
           function multInputs() {
               var mult = 0;
               // for each row:
               $("tr.txtMult").each(function () {
                   // get the values from this row:
                   var $val1 = $('.val1', this).val();
                   var $val2 = $('.val2', this).val();
                   var $total = ($val1 * 1) * ($val2 * 1);
                   // set total for the row
                   $('.multTotal', this).text($total);
                   mult += $total;
               });
               $("#grandTotal").text(mult);
           }
      });
    

    Working demo: http://jsfiddle.net/nnnnnn/5FpWC/

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

Sidebar

Related Questions

I want to calculate number of used columns for each row in excel 2007
I want to calculate the frequency of each word in a string. For that
I want to calculate a new date by adding a number of months to
I want to calculate total memory used by a process in .net. Total memory
I am trying to calculate totals for each row as well as a percentage
I'm building an interface that will calculate a total (based on neighboring inputs) when
I want to calculate the each and every method execution time like profiler do..
I want to calculate distance in my custom repository class. The problem is that
I want to calculate the smallest integer with exactly k bits set, that is
We want to calculate the value of an integral in linear plot. For a

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.