JavaScript Select and deselect all code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax checkbox code document function html javascript name

<script type= "Text/javascript Tutorial" >

function Checkall (name)
{
var names=document.getelementsbyname (name);
var len=names.length;
if (len>0)
{
var i=0;
for (i=0;i<len;i++)
Names[i].checked=true;

}
}

No choice.
function Checkallno (name)
{
var names=document.getelementsbyname (name);
var len=names.length;
if (len>0)
{
var i=0;
for (i=0;i<len;i++)
Names[i].checked=false;
}
}
</script>

html:

<input type= "checkbox" name= checkbox "value=" checkbox "onclick=" if (this.checked==true) {checkall (' gonggaoid ');} else {checkallno (' gonggaoid ');} />
Select All </label></td>
<input type= "checkbox" Name= "gonggaoid" value= "abc"/>

Method Two

<html>
<head>

<script type= "Text/javascript Tutorial" >

function Checkevent (name,allcheckid)
{
var Allck=document.getelementbyid (Allcheckid);
if (allck.checked==true)
Checkall (name);
Else
Checkallno (name);
All
function Checkall (name)
{
var names=document.getelementsbyname (name);
var len=names.length;
if (len>0)
{
var i=0;
for (i=0;i<len;i++)
Names[i].checked=true;

}
}

No choice.
function Checkallno (name)
{
var names=document.getelementsbyname (name);
var len=names.length;
if (len>0)
{
var i=0;
for (i=0;i<len;i++)
Names[i].checked=false;
}
}

Anti-election
function Reservecheck (name)
{
var names=document.getelementsbyname (name);
var len=names.length;
if (len>0)
{
var i=0;
for (i=0;i<len;i++)
{
if (names[i].checked)
Names[i].checked=false;
Else
Names[i].checked=true;

}
}

}

</script>
</head>

<body>

<input type= "checkbox" id= "Ckall" onclick= "checkevent (' ck ', ' ckall ')"/> Select all
<input type= "checkbox" id= "Ckreserve" onclick= "Reservecheck (' ck ', ' ckreserve ')"/> Reverse
<br/>
<input type= "checkbox" name= "CK" value= "1"/> Basketball
<br/>
<input type= "checkbox" name= "CK" value= "2"/> Tourism
<br/>
<input type= "checkbox" name= "CK" value= "3"/> Reading
<br/>
<input type= "checkbox" name= "CK" value= "4"/> Cuisine
<br/>
<input type= "checkbox" name= "CK" value= "5"/> Sleep
</body></html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.