SoFunction
Updated on 2025-02-28

Checkbox has various methods to select all the checkbox continuously updated Original


<script language=javascript>
//The first method
function selectall1()
{
   var a = ("input");
   if(a[0].checked==true){
   for (var i=0; i<; i++)
      if (a[i].type == "checkbox") a[i].checked = false;
   }
   else
   {
   for (var i=0; i<; i++)
      if (a[i].type == "checkbox") a[i].checked = true;
   }
}

//The second method

function selectall2() {
 var tform = ['form1'];
 for (var i=0;i<;i++)
 {
  var e = [i];
  if ( == "checkbox")
    = !;
 }
}

//The third method, combining the above two methods
function selectall3()
{
   var a = ("input");
   for (var i=0; i<; i++)
      if (a[i].type == "checkbox") a[i].checked =!a[i].checked;
  }
//The fourth method
function selectall4(id){ //Distinguish with id
var tform=['form1']; 
for(var i=0;i<;i++){ 
var e=[i]; 
if(=="checkbox" && ==id) =!; 

}
//The fifth method
function selectall(theform,thename){ //Theform specified form, thename is the name attribute of checkbox
var tform=[theform];
("thewen").value='Anti-select';
for(var i=0;i<;i++){
   var e=[i];
   if(=='checkbox' && ==thename)=!;
  }
}
</script>
<form  name="form1" method="post" action="">
  <input type="checkbox" name="sid" value="1" />
<input name="thes" type="button" onclick="javascript:selectall3()" value="Select All"/>
</form>