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">