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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:59:09+00:00 2026-06-04T06:59:09+00:00

I have 5 checkboxes in class check(named cb1, cb2, cb3, …) and 5 corresponding

  • 0

I have 5 checkboxes in class check(named cb1, cb2, cb3, …) and 5 corresponding textfields in class text(named tf1, tf2, tf3, …). When one or more checkboxes are checked I want to count all checked checkboxes and place the sum into the textfields that correspond when a button is clicked.

Example: If cb1 and cb3 are checked than tf1 and tf3 will have value 2.

So far I am counting total checked checkboxes like so:

$(':button').click(function() {
    total= $('.check:checked');
    count=total.length;
});

But I can’t figure out how to get ‘count’ in the corresponding textfields. Any help is appreciated!

P.S. I have different checkboxes and textfields in different classes so it is important they are referenced by class.

  • 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-04T06:59:10+00:00Added an answer on June 4, 2026 at 6:59 am

    Perhaps a little something like this:

    $(':button').click(function() {
        var total= $('.check:checked'),
            count=total.length;
    
        $('.text').val(function() {
           return $('#' + this.id.replace(/tf/,'cb')).is(':checked') ? count : 0;
        });
    });
    

    Each element with class text will be updated to have a value of either count or 0 depending on whether its corresponding checkbox is checked. Obviously if you’d prefer you can blank out the fields corresponding to unchecked checkboxes by replacing 0 with '' (empty string).

    (For more information on passing a function to the .val() method, read the doco.)

    Note that you should always declare your variables with var or you create globals.

    Working demo: http://jsfiddle.net/aBSNy/

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

Sidebar

Related Questions

I have a listbox of checkboxes that I want to iterate through and check
I have a group of checkboxes in a div and I use a check
I have a table setup like this: <table> <thead> <th> <input type=checkbox class=check-all />
I have added checkbox in display table using decorator class as shown in below
If I have Checkboxes in page with IDs like below a_chk1, a_chk2, a_chk3, b_chk1,
For example, i have checkboxes: <input type='checkbox' name='fruit' value='apple'> Apple <input type='checkbox' name='fruit' value='orange'>
He, I have this page where i have checkboxes next to every item in
I have a question on checkboxes in acess 2003 I have 4 checkboxes on
I have 10 checkboxes that are scattered throughout a page and if any one
I have several checkboxes and I am trying to take a lazy approach of

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.