JavaScript full selection and total elimination code

Source: Internet
Author: User
If the currently selected quantity is not selected and the Full selection box is selected, the status of the marquee is changed to no selection

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>javascript Full selection (total elimination), dynamic selection total elimination </TITLE>
<script type= "Text/javascript" language= "JavaScript" >
function Checkall ()//This method is used to select all and eliminate check boxes
{
var items=document.getelementsbyname ("Checkc");
var Itemall=document.getelementbyid ("All");
for (Var i=0;i<items.length;i++) {
items.checked=itemall.checked;
}
}
function Resall () {
var items=document.getelementsbyname ("Checkc");
var Itemall=document.getelementbyid ("All");
var ite=0; This variable is used to record the number of currently selected checkbox
for (Var i=0;i<items.length;i++) {
Get the number of currently selected checkbox
if (items.checked) {
ite++;
}
}
If the currently selected quantity is not selected, and the Full selection box is selected
The status of the marquee is changed to no selection
if (ite==items.length-1&&itemall.checked) {
Itemall.checked=false;
}
/*---
This applies to you want to remove the option to remove the full selection effect
if (ite==0&&itemall.checked) {
Itemall.checked=false;
}
---*/
If the currently selected quantity is zero and the full selection box is unchecked
Changes the status of the marquee to a selection
if (ite==items.length&&!itemall.checked) {
Itemall.checked=true;
}
}
</script>
</HEAD>
<BODY>
This script is suitable for use when the database is dynamically created, because there is no need to pass parameters inside. So scalability is not very high <br/>
<input type= "checkbox" Name= "All" id= "All" onclick= "Checkall ()" > select All

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >1

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >2

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >3

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >4

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >5

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >6

<input type= "checkbox" Name= "CHECKC" onclick= "Resall ()" >7

</BODY>
</HTML>



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.