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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:24:13+00:00 2026-05-16T22:24:13+00:00

Say when a checkbox is checked/unchecked, I want specific behavior to occur. Now if

  • 0

Say when a checkbox is checked/unchecked, I want specific behavior to occur.

Now if there are multiple points in my code where I set a checkbox as checked/unchecked, I have to run through the same logic ever time.

What is a way I can encapsulate the logic that occurs when a checkbox is checked, and just re-use that logic?

  • 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-16T22:24:14+00:00Added an answer on May 16, 2026 at 10:24 pm

    My guess is that you’re currently binding click event handlers like this:

    $('some-selector').click(function (event)
    {
        // do fancy stuff here
    });
    

    To encapsulate that logic, you just need to switch from using an anonymous function, to a function that you can reuse, like this:

    function handleClicks(event)
    {
        // do fancy stuff here
    }
    
    $('some-selector').click(handleClicks);
    $('some-other-selector').click(handleClicks);
    

    How’s that?


    I might also take a guess at the fact that the logic you’re writing and rewriting is to wire a “check-all” sort of checkbox to a group of checkboxes. I wrote a jQuery plugin recently to handle exactly this sort of thing.

    I never got around to uploading it properly to GitHub – here’s the gist of it. Let me know if you’d like to actually use it, and I can explain its usage – it’s pretty darn simple.

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

Sidebar

Related Questions

I have the following: $('input[name=myCheck]').change(function() { $('input:checkbox').removeAttr('checked'); }); How do I say: removeAttr('checked') for
I have a grid with one TemplateField which is a checkbox and say 2
Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
I have dynamic page. There are multiple checkboxes & I am using this script
Say I have this <table border=1 id=tbl> <tr> <td><input type=checkbox name=vehicle value=Bike /></td> <td>row
On a form I have, there are two checkboxes, say Master and Slave. Whenever
I've got a checkbox that's set up as below: <asp:CheckBox ID=myCheckbox runat=Server OnClick=showLoadingScreen(this.checked); AutoPostBack=true
I am working on struts2. I have 3 checkbox in my jsp page (say
I want a checkbox that is invisible in its unchecked state. While unchecked, hovering
I am adding the following code to check whether a checkbox should be checked

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.