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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:51:21+00:00 2026-05-25T15:51:21+00:00

I have a table whose values are generated dynamically with PHP. Each row in

  • 0

I have a table whose values are generated dynamically with PHP. Each row in the table has a checkbox. In the table is a header column, that has a “Accept All” button.

When a user clicks the “Accept All” button, all select boxes are checked. However, I want to add a toggle-like functionality: if no boxes are checked, then pressing the button selects all; if all boxes are checked, then pressing the button would unselect all.

Here’s my JQuery code for select all:

//Approves all
$('#approve_all_questions').click(function () {
    $("INPUT[type='checkbox']").attr('checked', true);
});

I’m having trouble getting it to toggle correctly. I’ve tried this:

//Toggle
$('#approve_all_questions').click(function () {

    if($("INPUT[type='checkbox']").attr('checked', true))
    {
        $("INPUT[type='checkbox']").attr('checked', false);
    }
    else
    {
        $("INPUT[type='checkbox']").attr('checked', true);
    }
  });

But that doesn’t work.

TIA.

  • 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-25T15:51:21+00:00Added an answer on May 25, 2026 at 3:51 pm

    $("INPUT[type='checkbox']").attr('checked', true) sets the checked attribute to true and returns a jQuery object which always evaluates to true.

    Maybe you want

    $("input[type='checkbox']").prop('checked', function(i, val) {
        return !val;
    });
    

    which inverts the checked value for each checkbox.

    If you want to select or deselect all at once, you could do:

    var $boxes = $("input[type='checkbox']"),
        $unselected = $boxes.not(function(){ 
            return this.checked;
        });
    
    // if there are any unselected boxes, it selects all, else it deselects all
    $boxes.prop('checked', $unselected.length > 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a column whose values come from an Enumeration. I
Suppose that I have an n -sided loaded die, where each side k has
We have a database with a table whose values were imported from another system.
Folks, I have a custom WebPart (the ASP.Net variety) that has a property whose
I have a table whose primary key is used in several other tables and
I have a table whose columns are varchar(50) and a float . I need
I have an Events table whose goal is to store actions done by web
I have a Tags table whose schema consists of only ID and Name (unique).
I have a simple table in MySql whose raison-d'être is to store logs. The
I have two table emptable1(empid,status) emptable2(empid,week) i want to select all the empid whose

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.