Solved

Javascript check all multiple checkbox groups

Posted on 2008-10-13
2
687 Views
Last Modified: 2010-04-21
Hello!

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?

thanks
<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";

}else{
 

for (i = 0; i < chk.length; i++)

chk[i].checked = false ;

document.search1.Check_All.value="Check All";

}

}
 

// End -->

</script>
 

***HTML***
 

<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"

onClick="Check(document.search1.check_list)">

Open in new window

0
Comment
Question by:allanch08
2 Comments
 
LVL 42

Accepted Solution

by:
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: http://www.dynamicsitesolutions.com/javascript/check-all-or-none-checkboxes/
0
 

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquey and footrable 2 33
Regular Expression 1-100 with two digits 15 21
Add css and js to MVC Project not in project 9 27
Use a select control to call a javascript function 5 29
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

943 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now