# Thursday, February 02, 2006
Thursday, February 02, 2006 1:25:33 PM (GMT Standard Time, UTC+00:00) ( Asp.Net )
<script language="javascript" type="text/javascript">
function Select(Select)
{
for (var n=0; n < document.forms[0].length; n++)
if (document.forms[0].elements[n].type=='checkbox')
document.forms[0].elements[n].checked=Select;
return false;
}
</script>


Select <a href="#" onclick="javascript:Select(true)">All</a> | <a href="#" onclick="javascript:Select(false)">None</a>

Comments [7] | | # 
Friday, July 14, 2006 2:52:35 AM (GMT Daylight Time, UTC+01:00)
How could this code be modified to check/uncheck all the checkboxes in a single CheckBoxList when multiple CheckBoxLists exists on the same page? CheckBoxList doesn't give all the checkboxes the Name value so attempting to group checkboxes by Name isn't possible.
Michael Hanes
Friday, July 14, 2006 7:56:42 AM (GMT Daylight Time, UTC+01:00)
Well it's probably not perfect but this might do the trick:

function selectAll (listId)
{
for (index = 0; index < checkBoxes.length; index++)
{
var currentCheckBox = checkBoxes [index];

if (currentCheckBox != null)
{
var currentCheckBoxId = currentCheckBox.id;

var lastUnderscoreIndex = currentCheckBoxId.lastIndexOf ('_');
var currentCheckBoxIdBaseId =
currentCheckBoxId.substring (0, lastUnderscoreIndex);

if (currentCheckBoxIdBaseId == listId)
{
currentCheckBox.checked = true;
}
}
}
}
Michael Hanes
Wednesday, April 16, 2008 6:40:17 PM (GMT Daylight Time, UTC+01:00)
function selectSwitch (listId, isChecked)
{
for (index = 0; index < document.forms[0].length; index++)
{
if (document.forms[0].elements[index].type=='checkbox')
{
var currentCheckBox = document.forms[0].elements[index];

if (currentCheckBox != null)
{
var currentCheckBoxId = currentCheckBox.id;

var lastUnderscoreIndex = currentCheckBoxId.lastIndexOf ('_');
var currentCheckBoxIdBaseId =
currentCheckBoxId.substring (0, lastUnderscoreIndex);

if (currentCheckBoxIdBaseId == listId)
{
currentCheckBox.checked = isChecked;
}
}
}
}
}
Two Years Too Late
Monday, October 06, 2008 12:36:35 PM (GMT Daylight Time, UTC+01:00)
How could this code be modified to check/uncheck all the checkboxes in a single CheckBoxList when multiple CheckBoxLists exists on the same page?
Hemant
Monday, October 06, 2008 12:38:21 PM (GMT Daylight Time, UTC+01:00)
hi hemant. have a read of the other comments, it's been asked and answered before! good luck. tim.
tim mackey
Wednesday, September 30, 2009 3:33:52 PM (GMT Daylight Time, UTC+01:00)
try this solution http://praveenbattula.blogspot.com/2009/09/aspnet-checkboxlist-get-values-in.html
Wednesday, September 30, 2009 3:34:47 PM (GMT Daylight Time, UTC+01:00)
Try this for simple logic to check and uncheck all or in specific div.
http://praveenbattula.blogspot.com/2009/09/checkuncheck-all-checkboxes-in-jquery.html
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview