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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:38:57+00:00 2026-06-16T11:38:57+00:00

I have a form that has multiple sets of checkboxes that initially load all

  • 0

I have a form that has multiple sets of checkboxes that initially load all checked. When the form is submitted arrays are built in the $_POST based on what checkboxes are “checked”. The entire form is built dynamically via PHP based on database data.

WHAT I’M LOOKING TO ACHIEVE:
I need a button or ‘clickable something’ that will toggle all of the checkboxes, within the group as all “not checked” then when the button is clicked again, it toggles all “checked” again. Or this could be achieved with two buttons. (whichever is cleaner / easier)

EXAMPLE:
(here are just two simple groups of checkbox array)
(each needs to be toggled independently of the other)
(I manually wrapped the code below to display it all in the box below)
(this example is just a representation of what the PHP code builds)
(two buttons are shown in the example but this would probably be best with a one “toggle all” button)

<form action="" method="post" enctype="multipart/form-data" name="filters">

Select: <input name="select_all_regions" onclick="toggle_all_regions()" 
          type="button" value="all" /> 
/ <input name="select_no_regions" onclick="toggle_no_regions()" 
          type="button" value="none" />
<input name="regions[]" type="checkbox" value="7" checked />East Coast
<input name="regions[]" type="checkbox" value="14" checked />West Coast
<input name="regions[]" type="checkbox" value="15" checked />Gulf Coast

Select: <input name="select_all_places" onclick="toggle_all_places()" 
          type="button" value="all" /> 
/ <input name="select_no_places" onclick="toggle_no_places()" 
          type="button" value="none" />
<input name="places[]" type="checkbox" value="25" checked />Dock
<input name="places[]" type="checkbox" value="29" checked />Ramp
<input name="places[]" type="checkbox" value="34" checked />Natural

<input class="filter-button" id="filter-submit-button" name="go" 
          type="submit" value="Go!" />

</form>

I’VE TRIED:
Javascript and jQuery but the “[]” seems to throw them both. I’m sure there is an easy solution but I’ve been unable to find it so far.

Thanks for taking a look!!!


UPDATE (so far):

I seem to be doing something wrong (it doesn’t work), is it obvious?

The Code I’ve Tried so far:

   <SCRIPT LANGUAGE="JavaScript"> 
    <!-- Begin 
    var $regions = $('input[name="regions[]"]');
    $('[name="select_all_regions"]').click(function(){
    $regions.prop('checked', !regions.first().is(':checked'));
    });
    // End --> 
    </script>

Select: <input name="select_all_regions" type="button" value="toggle all regions" /><br />

<input class="category-item-checkbox" name="regions[]" type="checkbox" value="7" checked /><span class="category-item-title">Uptown</span>
<input class="category-item-checkbox" name="regions[]" type="checkbox" value="14" checked /><span class="category-item-title">Warehouse District</span>
<input class="category-item-checkbox" name="regions[]" type="checkbox" value="15" checked /><span class="category-item-title">French Quarter</span>

SOLVED: (by Depot) See Below.

I’m sure the other solutions may work also but I wasn’t able to get them functional at this point.

THANK YOU ALL for looking at this!!! The StackOverflow community ROCKS!!!

  • 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-16T11:38:58+00:00Added an answer on June 16, 2026 at 11:38 am

    With your exact HTML without the onclick events, you could use:

    $('form[name="filters"]').click(function (e) {
        var match = e.target.name.match(/select_(all|no)_(.*)/);
        if (match) {
            $('input[name="' + match[2] + '[]"]').attr('checked', 'all' === match[1] && 'checked');
        }
    });
    

    DEMO

    or more simply:

    var $regions = $('input[name="regions[]"]'),
        $places = $('input[name="places[]"]');
    
    $('input[name="select_all_regions"]').click(function() {
        $regions.attr('checked', 'checked');
    });
    
    $('input[name="select_no_regions"]').click(function() {
        $regions.attr('checked', false);
    });
    
    $('input[name="select_all_places"]').click(function() {
        $places.attr('checked', 'checked');
    });
    
    $('input[name="select_no_places"]').click(function() {
        $places.attr('checked', false);
    });
    

    ​DEMO

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

Sidebar

Related Questions

i have a form that has select element <select name=adddisplaypage[] id=adddisplaypage multiple=multiple> <option value=all
I have a form that has multiple categories. They are separated by checkboxes, so
i have a form that has a multiple select drop down. a user can
I have a form that has a group of 13 checkboxes that together make
i have form that has multiple input text boxes, Which has got some text
If I have a form element that has multiple validators attached to it (3
I have a web page that has multiple tabs, which all do basically the
I have a form that has multiple select drop downs. i.e. Item 1: <select
I have a main form that has multiple buttons on it that will allow
have an access database with a form that has multiple textboxes for production data.

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.