Javascript check all multiple checkbox groups

Posted on 2008-10-13
Last Modified: 2010-04-21

I'm using the script below to check all checkboxes in a group. This works for one group in a form when the checkboxes have the same id.

 How can I modify this for more than one group in the same form?

<script language ="javascript">
<!-- Begin
function Check(chk)
if(document.search1.Check_All.value=="Check All"){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
document.search1.Check_All.value="UnCheck All";
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
document.search1.Check_All.value="Check All";
// End -->
<input name="colour_black" type="checkbox" id="check_list" value="1" />
<input name="colour_white" type="checkbox" id="check_list" value="1" />
<input type="button" id="Check_All" value="Check All"

Open in new window

Question by:allanch08
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 42

Accepted Solution

David S. earned 350 total points
ID: 22706193
IDs must be unique. Two elements in the same document may not have the same ID.

Perhaps this will help you:

Author Closing Comment

ID: 31505661
thanks kramivir, that's what I was looking for and the unique ID has cleared up another lingering question!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Debugging Html 8 32
Link Anchor Not working 9 51
Put POST values into cookies. 14 35
close pop up windows when logout or main window closes 17 56
In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question