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

The Archive Base Latest Questions

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

I have a somewhat large form that takes monetary values and has a total

  • 0

I have a somewhat large form that takes monetary values and has a total sum at the end. I am trying to automatically update the total using javascript (jQuery). Some of the input fields are optional. I am looking at using the .change() method. Is there a better way than to associate a change method with every single input field?

The script just needs to take the values from the input fields (if any), add them up and display the total somewhere. My idea was to tag each of the relevant input fields and select them. Is this possible?

[edit]
example code:

<input name="input1" type"text" />
<input name="input2" type"text" />
<input name="input3" type"text" />
<input name="input4" type"text" />
<input name="input5" type"text" />
<input name="input6" type"text" />

<input name="total" type="text" />

All the inputs are initially blank. I want the total to update as I enter values into the inputs.

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

    If you add a class (call it "foo") to each input element that you want to total up, then this will work:

    var $form = $('#my-form-id'),
        $summands = $form.find('.foo'),
        $sumDisplay = $('some-other-selector');
    
    $form.delegate('.foo', 'change', function ()
    {
        var sum = 0;
        $summands.each(function ()
        {
            var value = Number($(this).val());
            if (!isNaN(value)) sum += value;
        });
    
        $sumDisplay.text(sum);
    });
    

    Demo: http://jsfiddle.net/mattball/XcYTc/

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

Sidebar

Related Questions

I have a somewhat large server process written in .net-3.5, that is, running in
I have a very large Form with many date fields that need to be
I have a (somewhat) large truth table / state machine that I need to
I have just discovered Chosen . The library is somewhat large, especially that I
I have several somewhat separate programs, that conceptually can fit into a single project.
The task I have is to (somewhat efficiently) read line-by-line through a very large,
I've inherited a rather large and somewhat messy codebase, and have been tasked with
I have a large collection of scanned images, and they are all somewhat skewed,
I have a somewhat large output text file where I need to delete all
Say I have a somewhat large (i.e. not fit in most phones' memory) bitmap

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.