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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:14+00:00 2026-05-26T16:56:14+00:00

Based on the article How to increase the value of a quantity field I

  • 0

Based on the article “How to increase the value of a quantity field” I tried to find a way how I can get an action on multiple fields with one click on the +/-button.

What i like to get as an result is: When I click on the (+)button the one field will be increased by 1 and in the same moment the field “bestand1” will be decreased by one – and also the other way round: Increasing the one causes decreasing the other in the same moment.

Here is what I tried based on the other article:

<script type="text/javascript">
$(function()
{
    $(".add").click(function()
    {
        var currentVal = parseInt($(this).next(".qty").val());
        var bestandVal = parseInt($(this).next(".bestand").val());

        if (currentVal >= 10)
        {
            $(this).next(".qty").val(currentVal = 10);
        }
        if (currentVal != NaN && currentVal < 10)
        {
            $(this).next(".qty").val(currentVal + 1);
            $(this).next(".bestand").val(bestandVal - 1);
        }  
    });

    $(".minus").click(function()
    {
        var currentVal = parseInt($(this).prev(".qty").val());
        var bestandVal = parseInt($(this).prev(".bestand").val());

        if (currentVal <= 0)
        {
            $(this).next(".qty").val(currentVal = 0);
        }
        if (currentVal != NaN && currentVal > 0)
        {
            $(this).prev(".qty").val(currentVal - 1);
            $(this).prev(".bestand").val(bestandVal - 1);
        }

    });
});

</script>
</head>

<body>

    <form id="myform">
        bestand1
        <input type="text" id="bestand1" value="20" class="bestand" disabled /><br /><br />
        bestand2
        <input type="text" id="bestand2" value="20" class="bestand" disabled /><br /><br />
        product1
        <input type="button" value="+" id="add1" class="add" />        
        <input type="text" id="qty1" value="2" class="qty" disabled/>        
        <input type="button" value="-" id="minus1" class="minus" /><br /><br />

        product2
        <input type="button" value="+" id="add2" class="add" />        
        <input type="text" id="qty2" value="2" class="qty" disabled/>        
        <input type="button" value="-" id="minus2" class="minus" />

    </form>

</body>
  • 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-26T16:56:15+00:00Added an answer on May 26, 2026 at 4:56 pm

    Here it is, assuming you keep add1 and minus1 linked to qty1 and bestand1, and 2…etc

    $(function()
    {
        $(".add").click(function()
        {
            // get id number of the calling elememnt
            var num = parseInt(this.id.substr(3));
    
            // get jquery elements
            var el_qty = $("#qty"+num);
            var el_bes = $("#bestand"+num);
    
            // get current values
            var currentVal = parseInt(el_qty.val());
            var bestandVal = parseInt(el_bes.val());
    
            if (currentVal != NaN && currentVal < 10)
            {
                // increment values
                el_qty.val(++currentVal);
                el_bes.val(--bestandVal);
            }
        });
    
        $(".minus").click(function()
        {
            // get id number of the calling elememnt
            var num = parseInt(this.id.substr(5));
    
            // get jquery elements
            var el_qty = $("#qty"+num);
            var el_bes = $("#bestand"+num);
    
            // get current values
            var currentVal = parseInt(el_qty.val());
            var bestandVal = parseInt(el_bes.val());
    
            if (currentVal != NaN && currentVal > 0)
            {
                // increment values
                el_qty.val(--currentVal);
                el_bes.val(--bestandVal);
            }
    
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an article based website where users can login, post articles etc. The
I tried configuring log4r with Rails 3.0.4 based on this article: http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/ /Users/toto/.rvm/gems/ruby-1.9.2-p0/gems/log4r-1.1.9/lib/log4r/yamlconfigurator.rb:166:in `sub!':
My question is based on this article . Basically a class can implement a
Based on this article , it seems like SO is using Javascript OpenID Selector
I happened across this article about hardware based hard drive encryption and realized that
When I saw this article about using a python-like sintax (indentation based, without curly
Based on all my reading there should be one GC thread to invoke all
I have read many article about this one. I want to hear from you.
I'm implementing a Announcement system that is loosely based on this article: https://web.archive.org/web/20211020111733/https://www.4guysfromrolla.com/articles/110409-1.aspx One
I'm trying to use PowerShell with web deployment based on this article This 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.