Javascript check all multiple checkbox groups


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

Who is Participating?
David S.Connect With a Mentor Commented:
IDs must be unique. Two elements in the same document may not have the same ID.

Perhaps this will help you:
allanch08Author Commented:
thanks kramivir, that's what I was looking for and the unique ID has cleared up another lingering question!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.