Monday, January 24, 2011

Javascript : Simple Check Uncheck all checkbox



/* Here is the complete code */


<html>
 <head>
  <title> Check - Uncheck all checkbox </title>
 </head>
 <script language="javascript">
    function checkedAll (frm1)
    {
        var aa= document.getElementById('frm1');
       
        for (var i =0; i < aa.elements.length; i++)
        {
            aa.elements[i].checked = true;
        }
    }
   
    function uncheckedAll (frm1)
    {
        var aa= document.getElementById('frm1');
       
        for (var i =0; i < aa.elements.length; i++)
        {
            aa.elements[i].checked = false;
        }
    }

 </script>
 <body>
  Select : <a href="#" onclick="checkedAll();">All</a>/<a href="#" onclick="uncheckedAll();">None</a> <br/>
  <form id="frm1">
  <input id="chk" type="checkbox"> Java <br/>
  <input id="chk" type="checkbox"> J2ee <br/>
  <input id="chk" type="checkbox"> Javascript <br/>
  <input id="chk" type="checkbox"> Linux <br/>
  <input id="chk" type="checkbox"> Oracle <br/>
  </form>
 </body>
</html>

Output