Hello Friends,
It is a simple script for selecting all check box in javascript. You need to put these functions in
tag. It will select all checkbox of that form. You can call them on a link or image. like this -<a href="javascript:selectall()">Select All</a> <a href="javascript:unselectall()">UnSelect All</a>
Concept is simple, we are just counting no. of checkbox of the form and then looping them to check if each checkbox is selected to make it unselect in unselectall and vise versa in selectall function.
Here is that javascript functions –
<script language="javascript">
function selectall()
{
var len=document.myform.elements.length;
var scrapcount=0;
for(scrapcount=0;scrapcount<=len; scrapcount++)
{
if(document.myform.elements[scrapcount].type=='checkbox')
{
document.myform.elements[scrapcount].checked=true;
}
}
}
function unselectall()
{
var len1=document.myform.elements.length;
var scrapcount1=0;
for(scrapcount1=0;scrapcount1<=len1; scrapcount1++)
{
if(document.myform.elements[scrapcount1].type=='checkbox')
{
document.myform.elements[scrapcount1].checked=false;
}
}
}
</script>
Enjoy it..

Leave a Reply