JavaScript Applications: Implementing check box selection/all switch

Source: Internet
Author: User
check box

<input Type=checkbox name=mm value=a ><br>
<input Type=checkbox name=mm value=b ><br>
<input Type=checkbox name=mm value=c ><br>
<input Type=checkbox name=mm Value=d ><br>
<input Type=checkbox name=mm value=e ><br><br>
<input Type=checkbox Name=mmall > Full selection and optional switching

<script language=javascript>
function Checkall (e, ItemName)
{
var AA = Document.getelementsbyname (itemname);
for (var i=0; i<aa.length; i++)
aa[i].checked = e.checked;
}
function Checkitem (e, Allname)
{
var all = Document.getelementsbyname (Allname) [0];
if (!e.checked) all.checked = false;
Else
{
var AA = Document.getelementsbyname (e.name);
for (var i=0; i<aa.length; i++)
if (!aa[i].checked) return;
All.checked = true;
}
}
</script>

PS: (Of course, if the full selection of the box is another control such as a button, or a link to anything, the checkbox in the Checkitem Click event can be removed to avoid errors)



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.