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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:08:32+00:00 2026-06-09T18:08:32+00:00

I could really your help! I need to sum a dynamic amount of textboxes

  • 0

I could really your help! I need to sum a dynamic amount of textboxes but my JavaScript knowledge is way to week to accomplish this. Anyone could help me out? I want the function to print the sum in the p-tag named inptSum.

Here’s a function and the html code:

function InputSum() {
    ...
}

<table id="tbl">
<tbody>
    <tr>
        <td align="right">
            <span>June</span>
        </td>
        <td>
            <input name="month_0" type="text" value="0" id="month_0" onchange="InputSum()" />
        </td>
    </tr>
    <tr>
        <td align="right">
            <span>July</span>
        </td>
        <td>
            <input name="month_1" type="text" value="0" id="month_1" onchange="InputSum()" />
        </td>
    </tr>
    <tr>
        <td align="right">
            <span>August</span>
        </td>
        <td>
            <input name="month_2" type="text" value="0" id="month_2"  onchange="InputSum()" />
        </td>
    </tr>
    <tr>
        <td align="right">
            <span>September</span>
        </td>
        <td>
            <input name="month_3" type="text" value="0" id="month_3" onchange="InputSum()" />
        </td>
    </tr>
    </tbody>
</table>

<p id="inputSum"></p>
  • 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-09T18:08:34+00:00Added an answer on June 9, 2026 at 6:08 pm

    With a little jQuery, you could do it quite easily, using the attribute starts with selector. We then loop over them, parses their values into integers and sum them up. Something like this:

    function InputSum() {
        var sum = 0;
        $('input[id^="month_"]').each(function () {
            sum += parseInt($(this).val(), 10);
        });
        $("#inputSum").text(sum);
    }
    

    You could even get rid of the onchange attributes on each input if you modify the code to something like this:

    $(function () {
        var elms = $('input[id^="month_"]');
        elms.change(function() {
            var sum = 0;
            elms.each(function () {
                sum += parseInt($(this).val(), 10);
            });
            $("#inputSum").text(sum);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a security problem here and we really need your help and inputs.
I'm new to Java and really need your help. I am presently using a
Good day. I could really use your help on this one. I have a
I could really do with some help here. I've spent the past couple of
I could really use some help here. I just created a new bare repo
I'am new to Python 3 and could really use a little help. I have
A really simple question but I could not figure it out... I tried to
I am really new to Ruby and could use some help with a program.
New question, but really close to need to refresh page in jquery mobile .
Math has come on my way again and has defeated me. I need your

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.