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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:34:42+00:00 2026-06-05T19:34:42+00:00

I have multiple input text fields grouped in divs: <div class=container0> <input class=containerItem0 name=containerItem[0][0]

  • 0

I have multiple input text fields grouped in divs:

<div class="container0">
<input class="containerItem0" name="containerItem[0][0]" id="containerItem_0_0" type="text">  
<input class="containerItem1" name="containerItem[0][1]" id="containerItem_0_1" type="text">
</div

<div class="container1">
<input class="containerItem0" name="containerItem[1][0]" id="containerItem_1_0" type="text">
<input class="containerItem1" name="containerItem[1][1]" id="containerItem_1_1" type="text">
</div>

<div class="container2">
<input class="containerItem0" name="containerItem[2][0]" id="containerItem_2_0" type="text">
<input class="containerItem1" name="containerItem[2][1]" id="containerItem_2_1" type="text">
</div>

Let me explain this code:
I have three containers: 0,1 and 2. However this is variable. There could be more or less.
In each container I always have the same number of items, in this case two. This can vary as well but it will always be the same amount across all containers.
The items with the same class are the same items! The only difference is that they are in different containers.
The name and ID for each input item is used in my php script to determine after submitting the form:

containerItem[1][0]
containerItem[ContainerNumber][Item]

What I want to accomplish:
There is a individual maximum amount for each containerItem.
Let’s say containerItem0 = 100, containerItem1 = 200, containerItem2 = 300.
Now when I enter a numeric value into the input field for containerItem0, e.g. 20. It should update a which could be behind the input field how much is left, in this case 80.
Not only should it update the behind the input field where I just entered the numeric value but behind all other containerItem0’s as well.

What I tried

// php part
// Create variables for use in jquery for the max values for the containerItems
$jqueryVars="";
$j=0;
// containerItems is an array I get with the numberOrdered value which equals the maximum number allowed
foreach ($containerItems as $key => $value) {
    $jqueryVars .= "var maxContainerItem".$j." = ".$value['NumberOrdered'].";\n";
    $j++;
}


// jQuery part:
// Calculate left amount of container items.
'$(document).change(function() {
    '.$jqueryVars.'
    var sumOfValues = 0;
    //I USED >>.containerItem0<< in this case to see if it works, however this should be variable
    $(".containerItem0").each(function(){
       sumOfValues+=$(this).val();
    });
    alert(sumOfValues);
});

As you can see I am stuck making this whole thing dynamic. I partially get the alert message of sumOfValues. Why partially? It does not add the numbers but appends them as they were strings.
Also, I do not know how to iterate through all container classes and listen for changes in the input fields.

I am looking forward to get any pointers into the right direction 🙂

  • 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-05T19:34:43+00:00Added an answer on June 5, 2026 at 7:34 pm

    You’re using $(this).val() which returns the value of the input fields. These values are indeed strings, so using + on them will concatenate them.

    If you parse the values before adding them, it should yield what you expect:

    $(document).change(function() {
      var sumOfValues = 0;
      $(".containerItem0").each(function() {
         sumOfValues += parseFloat($(this).val());
      });
      alert(sumOfValues);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple input fields. <input type='text' size='10' name='firstname' id='firstname' /> <input type='text' size='20'
Let's assume I have a form with these fields (HTML) <input type=text name=user[name] value=name/>
I have a setup with multiple form fields.. <input type='text' id='Trait1' >0</input> <input type='text'
I have form with multiple input type=radio with text next to them. I want
I have a form with multiple text input fields and sub-forms. Is there a
I've got multiple input fields where they have the same class names. I need
so I have a form that I have multiple input text fields as well
i have a form with multiple div elements like this <div> <label for=id>text</label> <input
I have multiple input textboxes in my page. I want to reset particular text
I have an HTML form that needs multiple submit buttons, like this: <input type=submit

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.