JavaScript Tips: List checkbox Select All

Source: Internet
Author: User
Javascript| Tips

Recently do a small project in the company, need to do a multiple-select items Delete function, so write the following JS script examples to achieve, in fact, is often used to compare the basis of things, the master will not have to see.


Program code:
<script language= "JavaScript">
<!--

function CA (frm)
{
var trk=0;
for (Var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name!= ' Allbox ') && (e.type== ')checkbox') && (e.name!= ' Don't want to be selectedcheckbox's name "))
{
trk++;
e.checked=frm.allbox.checked;
frm.del.disabled = frm.allbox.checked?false:true;//Select AllEffect on the disabled property of the Delete button
}
}
}

function CCA (FRM,CB)
{
var tb=to=0;
for (Var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name!= ' Allbox ') && (e.type== ')checkbox') && (e.name!= ' Don't want to be selectedcheckbox's name "))
{
tb++;
if (e.checked)
to++;
}
}
Frm.allbox.checked= (TO==TB) True:false;

if (0==to)//All unchecked and selected, the effect on the disabled property of the Delete button
{
Frm.del.disabled = true;
}
Else
{
frm.del.disabled = false;
}
}

-->
</script>


Call Method:
Select AllThe name of the Allbox is set,onclickEvent execution CA (this.form);
The Checbox of the selected item.onclickEvent execution CCA (this.form,this);



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.