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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:09:40+00:00 2026-05-29T11:09:40+00:00

This function alerts right totalqt only when I check checkboxes one by one. But

  • 0

This function alerts right totalqt only when I check checkboxes one by one. But doesn’t work properly for #check_all: alerts totalqt = 0.

What I did wrong, can anyone explain?

var totalqt=0;
   $('#check_all').click( function() {
        $('.checkbox').click();    
        alert(totalqt);
    } );    


 $('.checkbox').click(function(e) {
        e.stopPropagation();
        if($(this).closest("tr").not('#hdr').hasClass("row_selected")){
            $(this).closest("tr").not('#hdr').removeClass("row_selected");
            totalqt=totalqt - parseInt($(this).closest("tr").find("#qt").text(), 10);
        }
        else {
            $(this).closest("tr").not('#hdr').addClass("row_selected");
            totalqt=totalqt + parseInt($(this).closest("tr").find("#qt").text());
        }

HTML looks like that

<tr>
...
<td><input type="checkbox" name="checkbox[]" method="post" value="" class="checkbox"/></td>
...
</tr>
  • 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-29T11:09:41+00:00Added an answer on May 29, 2026 at 11:09 am

    actually when the checkbox is changed manualy it doesn’t trigger handler. try something like this.

    function doIt(obj){
           if($(obj).closest("tr").not('#hdr').hasClass("row_selected")){
                $(obj).closest("tr").not('#hdr').removeClass("row_selected");
                totalqt=totalqt - parseInt($(obj).closest("tr").find("#qt").text(), 10);
            }
            else {
                $(obj).closest("tr").not('#hdr').addClass("row_selected");
                totalqt=totalqt + parseInt($(obj).closest("tr").find("#qt").text());
            }
    }
    

    then

    $('.checkbox').click(function(e) {
            e.stopPropagation();
            doIt(this);
    });
    

    and

    $('#check_all').click( function() {
            if($(this).prop('checked')){
                $('.checkbox').each(function(){
                    $(this).prop('checked', true);    
                    doIt(this);
                    alert(totalqt);
               });
          }else{
    
               $('.checkbox').each(function(){
                    $(this).prop('checked', false);    
                    doIt(this);
                    alert(totalqt);
               });
          }
    
    } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a notification area that will show alerts. return this.each(function() {
Suppose I had the following function: function alertMesg() { alert(This ok function alerts message!);
I've got this function to check my form: function checkFrm() { $.each($('select'), function() {
I cant for the life of me figure out why this doesn't work: javascript:
EDIT: this works, but not sure why? $('button').each(function() { $(this).bind( click, function() { alert($(this).val());
I know this will work: function Foo() {}; Foo.prototype.talk = function () { alert('hello~\n');
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
This code function LoadContent(Id) { alert('Controls/Network/NetworkDetail.aspx?' + rnd() + '&CtlId=' + Id); $.get('Controls/Network/NetworkDetail.aspx?' +
I have this (simplification): $(li).click(function{alert(test);}); <li> <input> </li> What's the best way to bind
I have this at the top of my jQuery script: $().ajaxStart(function() { alert('ok'); });

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.