Follow Me

Select unselect all checkbox javascript

Tue, May 25, 2010

JavaScript

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>&nbsp;<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..

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • blogmarks
  • Design Float
  • DZone
  • MySpace
  • Reddit
  • StumbleUpon
  • Twitter
, , ,

Related Posts:


Recent Posts:

  • Best collection of firefox addons for web designers and developers
  • .htaccess basic features with example
  • how to include an external css and js with javascript dynamically
  • How to preserve line breaks in textarea mysql data
  • how to generate excel report with php and mysql
  • Leave a Reply