[JavaScript] Selects all check boxes, does not select all, and selects inverse check boxes.

Source: Internet
Author: User
Document directory
  • Select All or all
  • Invert Selection
  • Sample program

You can use a simple program to select all check boxes, select none, or select inverse ones.

In addition, you can set the variable part as the JS parameter for code reuse.

Select All or all

The first parameter is the check box name, and the second parameter is select all or not.

function allCheck(name,boolValue) {var allvalue = document.getElementsByName(name); for (var i = 0; i < allvalue.length; i++) {      if (allvalue[i].type == "checkbox")           allvalue[i].checked = boolValue;           }}

Invert Selection

The parameter is the name of the check box.

function reserveCheck(name){var revalue = document.getElementsByName(name); for(i=0;i<revalue.length;i++){   if(revalue[i].checked == true) revalue[i].checked = false;  else revalue[i].checked = true;}}

Sample program

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

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.