JS Judgment check box Select all, all do not select, counter-Select, must choose one

Source: Internet
Author: User

A good use of the JS code snippet, to determine the check box selection, all do not select, reverse selection, a must choose

Take a note, move it.

Ideas:

Modify the selected status of the data, get all the input boxes to see if there is a selected state

check box Select all, uncheck, reverse, must select one</title> <meta http-equiv= "Content-type" content= "TEXT/HTML;CHARSET=GBK"/> <script language= " JavaScript ">//Form Validation            functionCheck () {varids = Document.getelementsbyname ("IDs")); varFlag =false ;  for(vari=0;i<ids.length;i++){                    if(ids[i].checked) {flag=true ;  Break ; }                }                if(!flag) {Alert ("Please select at least one item!" "); return false ; }            }            //Select All            functioniselect () {//where the function number cannot be a select its JS reserved word                varids = Document.getelementsbyname ("IDs")); varall = document.getElementById ("All");  for(vari=0;i<ids.length;i++) {ids[i].checked=all.checked; }            }            //Select All            functionSelectAll () {varids = Document.getelementsbyname ("IDs"));  for(vari=0;i<ids.length;i++) {ids[i].checked=true; }            }            //all No            functionSelectnone () {varids = Document.getelementsbyname ("IDs"));  for(vari=0;i<ids.length;i++) {ids[i].checked=false; }            }            //Inverse Selection            functionSelectinvert () {varids = Document.getelementsbyname ("IDs"));  for(vari=0;i<ids.length;i++){                    if(ids[i].checked) ids[i].checked=false ; Elseids[i].checked=true ; }            }        </script> 

Script ">//form validation function check () {var ids = Document.getelementsbyname (" IDs "); var flag = false; for (Var i=0;i<ids. length;i++) {if (ids[i].checked) {flag = true; break;}} if (!flag) {alert ("Please select at least one item!"). "); return false; }}//Select All function iselect () {//The function number cannot be a select which is the JS reserved word var ids = document.getelementsbyname ("IDs"); var all = Document.gete Lementbyid ("All"); for (Var i=0;i<ids.length;i++) {ids[i].checked=all.checked;}} Select All function SelectAll () {var ids = Document.getelementsbyname ("IDs"); for (Var i=0;i<ids.length;i++) {Ids[i]. Checked=true; }}//All function Selectnone () {var ids = Document.getelementsbyname ("IDs"); for (Var i=0;i<ids.length;i++) {Ids[i].che Cked=false; }}//Counter-select function Selectinvert () {var ids = Document.getelementsbyname ("IDs"); for (Var i=0;i<ids.length;i++) {if (ids[i ].checked) Ids[i].checked=false; else ids[i].checked=true; }} </script>

JS judgment check box Select all, uncheck, reverse, a must select one

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.