Complete JavaScript checkbox selection, cancel all selection, and delete code

Source: Internet
Author: User

See the following two implementation methods:
JS checkbox Method 1: CopyCode The Code is as follows: function checkall ()
{
VaR code_values = Document. All ['Code _ value'];
If (code_values.length ){
For (VAR I = 0; I <code_values.length; I ++)
{
Code_values [I]. Checked = true;
}
} Else {
Code_values.checked = true;
}
}
Function uncheckall ()
{
VaR code_values = Document. All ['Code _ value'];
If (code_values.length ){
For (VAR I = 0; I <code_values.length; I ++)
{
Code_values [I]. Checked = false;
}
} Else {
Code_values.checked = false;
}
}
Function multipledelete ()
{
VaR num = 0;
VaR code_values = Document. All ['Code _ value'];
If (code_values.length ){
For (VAR I = 0; I <code_values.length; I ++)
{
If (code_values [I]. Checked = true)
{
Num ++;
}
}
} Else {
If (code_values.checked = true ){
Num ++;
}
}
If (num = 0 ){
Alert ('Please select Delete item ');
}
If (Num> 0 ){
Document. bucodesearch. Action = '<% = eusutil. getpage ("lookup. Generic. bucode. Delete. s") %> ';
Document. bucodesearch. Submit ();
}
}
</SCRIPT>

JS checkbox Method 2:
Copy code The Code is as follows: function checkall ()
{
VaR code_values = Document. getelementsbytagname ("input ");
For (I = 0; I <code_values.length; I ++ ){
If (code_values [I]. type = "checkbox ")
{
Code_values [I]. Checked = true;
}
}
}
Function uncheckall ()
{
VaR code_values = Document. getelementsbytagname ("input ");
For (I = 0; I <code_values.length; I ++ ){
If (code_values [I]. type = "checkbox ")
{
Code_values [I]. Checked = false;
}
}
}
Function multipledelete ()
{
If (document. bucodesearch. elements ["code_value"])
{
VaR num = 0;
VaR fm = Document. bucodesearch;
If (document. bucodesearch. elements ["code_value"])
{
VaR elm = Document. bucodesearch. elements ["code_value"];
VaR ename = "code_value ";
If (ELM. Length ){
VaR Len = FM. elements [ename]. length;
For (VAR I = 0; I <Len; I ++ ){
VaR E = FM. elements [ename] [I];
If (E. Checked = true ){
Num ++;
}
}
} Else {
If (ELM. Checked = true ){
Num ++;
}
}
If (Num> 0)
{
Document. bucodesearch. Action = '<% = eusutil. getpage ("lookup. Generic. bucode. Delete. s") %> ';
Document. bucodesearch. Submit ();
}
}
}
}

Code_value is the name of the checkbox form, and bucodesearch is the form name.Copy codeThe Code is as follows: <TD align = "Left" width = "20"> <input type = "checkbox" name = "code_value" value = "<% = userdeffieldvaluebean. getudfvalue () %> "> </TD>

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.