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

  • Home
  • SEARCH
  • 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 9188437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:00:28+00:00 2026-06-17T20:00:28+00:00

I’m trying to get an autosum from fields, the issue is that if the

  • 0

I’m trying to get an autosum from fields, the issue is that if the total of fields are without value the script is not working correctly, and also if there are more than 7 fields again the script is not working.

here is the javascript:

function getTotal()
{
    var value01 = document.getElementById('value01').value;
    var value02 = document.getElementById('value02').value;
    var value03 = document.getElementById('value03').value;
    var value04 = document.getElementById('value04').value;
    var value05 = document.getElementById('value05').value;
    var value06 = document.getElementById('value06').value;
    var value07 = document.getElementById('value07').value;

    // Add them together and display
    var sum = parseInt(value01) + parseInt(value02) + parseInt(value03) + parseInt(value04) + parseInt(value05) + parseInt(value06) + parseInt(value07);
    document.getElementById('sum_total').value = sum;
}

inputs:

<input type="text" id="value01" />
<input type="text" id="value02" />
<input type="text" id="value03" />
here is starting to be added with a button more input fields.
<input type="text" id="+" />
<input type="text" id="++" />
<input type="button" value="Add Them Together" onclick="getTotal();" />

my question is, how can i get an auto + on var value01 02 03 etc.

Any help is appreciated.

  • 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-17T20:00:30+00:00Added an answer on June 17, 2026 at 8:00 pm

    Your question is not very clear and so I’m not too sure what you are wanting to do so feel free to offer clarification for optimum assistance. On that note, based off of what you have provided, I have two things to point out:

    1) Your ID of “+” is not valid. Per the HTML 4 spec:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
    followed by any number of letters, digits ([0-9]), hyphens (“-“),
    underscores (“_”), colons (“:”), and periods (“.”).

    2) Instead of creating a different var containing each value, I would recommend creating a function that you can use within a for loop that will determine the sums of each incremental input. This is more DRY and helps simplify things if the number of inputs were to grow.

    function getValues(id){
        return document.getElementById(id).value;
    }
    

    The pure JavaScript solution below begins with one input box and will add additional inputs with the click of a button, which I believe is what you’re looking for. You can modify the number of initial input boxes accordingly, but it should give you an idea.

    Javascript:

    var max = 1;
    
    function getValues(id){
        var result = document.getElementById(id).value;
        return (result ? result : 0);
    }
    
    function addInput(){
        max++;
        var input = '<input type="text" id="value'+ max +'" />';
        document.getElementById("valuesContainer").innerHTML += input;
    }
    
    function getTotal(){
        var sum = 0;
        for(var i=1; i <= max; i++){
            sum = sum + parseFloat(getValues("value" + i));
        }
        document.getElementById("total").innerHTML = sum;
    }
    

    HTML:

    <div id="valuesContainer">
    <input type="text" id="value1" />
    </div>
    <input type="button" value="Add Value" id="addMore" onclick="addInput();" />
    <input type="button" value="Calculate Total" onclick="getTotal();" />
    <div id="total"></div>
    

    Demo: http://jsfiddle.net/Y4xgU/

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is

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.