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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:26:08+00:00 2026-05-21T10:26:08+00:00

I am using jquery calculation to do a sum on one of my client

  • 0

I am using jquery calculation to do a sum on one of my client pages. Simple calculation is working fine but I have to integrate an add and remove button with the input tags. As in instead of manually entering a number client wants to use add and remove button to increase and decrease the value of the product and eventually adding up to the totalSum.

Hoping someone can help me with this as I am not yet an expert in jquery. 🙂

Here the HTML code

<div class="amount">    
            <input type="text" class="count"  name="totalSum" id="totalSum" value="" size="2" readonly="readonly">                      </div>



    <div class="clearfix"></div><!--Please do not delete this div-->
    <!--Case 1-->       
    <div class="bottle_in_case">
                <div class="addRemove">
                <input type="text" value="2" class="count" maxlength="2" name="case" id="case_1"> bottles
                <p class="add_remove_btns"><a href="#"><img src="images/add.gif" alt=""> Add</a> / <a href="#"><img src="images/remove.gif" alt=""> Remove</a></p>
            </div>
    </div>

    <!--Case 2-->       
    <div class="bottle_in_case">

        <div class="addRemove">
                <input type="text" value="2" class="count" maxlength="2" name="case" id="case_2"> bottles
                <p class="add_remove_btns"><a href="#"><img src="images/add.gif" alt=""> Add</a> / <a href="#"><img src="images/remove.gif" alt=""> Remove</a></p>
            </div>
    </div>

    <!--Case 3-->       
    <div class="bottle_in_case last">

            <div class="addRemove">
                <input type="text" value="2" class="count" maxlength="2" name="case" id="case_3"> bottles
                <p class="add_remove_btns"><a href="#"><img src="images/add.gif" alt=""> Add</a> / <a href="#"><img src="images/remove.gif" alt=""> Remove</a></p>
            </div>
    </div>

The Script I have used is

$("input[name^='case']").sum();

$(“input[name^=case]”).sum(“keyup”, “#totalSum”);

Thanks in advance

Neha

  • 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-21T10:26:09+00:00Added an answer on May 21, 2026 at 10:26 am

    First things first: to attach a quantity changer to the add.gif and remove.gif:

    <p class="add_remove_btns"><a href="#"><img src="images/add.gif" alt=""> Add</a> / <a href="#"><img src="images/remove.gif" alt=""> Remove</a>
    

    Change all instances of above to

    <p class="add_remove_btns"><a href="#" class="add_qty" rel="1"><img src="images/add.gif" alt=""> Add</a> / <a href="#" class="remove_qty" rel="1"><img src="images/remove.gif" alt=""> Remove</a>
    

    Of course each instance of rel=”1″ or rel=”2″ would have to correspond with the id=”case_1″ ‘s numbers…

    Now in the jQuery (running on document ready syntax)

    $('add_qty').each(function(){
      $(this).click(function() {
        var target = $(this).attr('rel');
        var newqty = $('#case_'+target).val()+1;
        $('#case_'+target).val(newqty);
        recalculate_total();
        return false;
      });    
    });
    
    $('remove_qty').each(function(){
      $(this).click(function() {
        var target = $(this).attr('rel');
        var newqty = $('#case_'+target).val()-1;
        if(newqty<0) {newqty=0;} // qty cannot be below 0, so override to 0 if thats the case
        $('#case_'+target).val(newqty);
        recalculate_total();
        return false;
      });    
    });
    

    To get the sum of all the rows, create this function OUTSIDE the document ready syntax:

     function recalculate_total() {
        var total = 0;
        $('input.count').each(function(){
        total = total+$(this).val()*1;
        });
        $('#totalSum').val(total);
        }
    

    Let me know if this works.. provide a URL for me too so I can troubleshoot if there is an error.

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

Sidebar

Related Questions

I'm using the jQuery calculation and have just about everything working properly, but I
I have a code in javascript and I am using jQuery Calculation plugin (can
I have been using jquery validate plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation/ . It has been working successfully,
Using jQuery, how would you find elements which have a particular style (eg: float:
i am trying to sum up or deduct dates in selected range using jquery
I'm using JQuery Calculation plugin with the following script: function recalc() { jQuery(input[class^=percent]).calc( (invoice
I am using both JQuery UI Dialog and JQuery UI autocomplete both have the
I'm building a webapp using JQuery, Stripes, Spring and JPA (Hibernate). I have a
I have my object tracking the mouse using the onmousemove event. But I would
I'm using jQuery in my project by the jQuery and jQuery-ui plugins. I have

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.