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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:24:08+00:00 2026-06-03T12:24:08+00:00

I have several checkboxes with the same name, and values that are a power

  • 0

I have several checkboxes with the same name, and values that are a power of 2:

<input type=checkbox name=mycheckbox value=1>Some text 1
<input type=checkbox name=mycheckbox value=2>Some text 2
<input type=checkbox name=mycheckbox value=4>Some text 3
<input type=checkbox name=mycheckbox value=8>Some text 4
<input type=checkbox name=mycheckbox value=16>Some text 5
<input type=checkbox name=mycheckbox value=32>Some text 6

The value stored in the database is the bitwise OR of the selected checkboxes, so if Some text 3 and Some text 6 are checked, the value in the database will be 32 | 4 = 36.

I load this value from the database using an Ajax call. What would be the easiest or best way using jQuery to check the appropriate checkboxes based on the number?

I’m more used to doing scripting and would approach it like:

for (i = 1; i <= 32; i*=2)
   if ((ajaxValue & i) == i)

etc.

But ideally jQuery could do it much easier, and check the checkboxes by value.

  • 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-03T12:24:10+00:00Added an answer on June 3, 2026 at 12:24 pm
    $(function () {
      $('input[name=mycheckbox]').each(function () {
        // Your code there like if ($(this).val() ....
        if ($(this).val() == someValue) $(this).attr('checked', 'checked'); // Example of make the checkbox checked
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several like this in my HTML code: <input class=table type=checkbox name=interest[] value=finger
I have several Jenkins parameterized jobs that uses the same parameters and parameters values.
I'm generating several check boxes that all have the same name, when the form
I have a several columns of :checkboxes and labels. <ul class=column1> <li> <input value=jan
i have several checkboxes that when checked show a hidden div. Is there a
I have a form which have five buttons and several checkboxes holding different values.
I have made a function that if i check a checkbox an text will
I have a small application that has several checkboxes, a submit button, and a
I have a datagrid that has several things where it has dropdowns checkboxes and
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.