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

The Archive Base Latest Questions

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

What I want is to store the sum for a database object with id

  • 0

What I want is to store the sum for a database object with id 3. (see input tags below)
I have many different id’s with different values. The value in the sample below I want to store is 2.

Besides that I want to increase/decrease the value of sum[3] using a “+” and a “-” button with JavaScript. So I created a function called incr and decr to do that:

<script type="text/javascript">
function incr(what)
{
    alert(what);
    what.value ++;

    // rest of the function I left out, it works with a 'normal' name of the input tag
    //but I need to use the array
}    
</script>

how many?<input type="text" size="10" name="sum[3]" value="2" />
<input name="plus" type="button" value="+" onclick="incr(document.sum[3])" />
<input name="min" type="button" value="-" onclick="decr(document.sum[3])" />

I can’t get it working, even the alert doesn’t return a value. Anybody?

  • 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-14T03:23:34+00:00Added an answer on June 14, 2026 at 3:23 am

    This is not the most elegant approach as it is using lots of inline code, but it solves your problem. What went wrong with your approach is that document.sum[3] is not the correct selector the the name=”sum[3]” input

    <script type="text/javascript">
    function incr(what)
    {
    
        what.value ++;
        alert(what.value);
        // rest of the function I left out, it works with a 'normal' name of the input tag
        //but I need to use the array
    }    
    </script>
    
    how many?<input type="text" size="10" name="sum[3]" value="2" />
    <input name="plus" type="button" value="+" onclick="incr(document.getElementsByName('sum[3]')[0])" />
    <input name="min" type="button" value="-" onclick="decr(document.getElementsByName('sum[3]')[0])" />
    

    You should consider using jQuery and refactoring the code with event handlers rather than using inline javascript.

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

Sidebar

Related Questions

I have to sum all the values in one object. The values are retrieved
I want to store a .NET object into Azure Blob Storage. Currently I serialize
I want to store the TF-IDF matrix so I don't have to recalculate it
I want to store a very long string in database using php. The size
I have a time value being stored in a database as a varchar(4) and
I have a PHP-based site with bookings/appointments stored in a MySQL database. I want
I have 2 different object types stored in RavenDb, which are a parent/child type
I have a pretty standard attendance database design, but I want to be alerted
I am a new developer on Android and I want store user data in
I want to store an image in my SQLITE db. I checked out the

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.