Javascript code for Selecting All and canceling all CheckBox _ form special effects

Source: Internet
Author: User
In batch processing of List data, all selection and cancellation of CheckBox are often used. Although her implementation principle is very simple, it is still difficult for new users. The method described in this article. The trigger conditions are independent. You can select or cancel all the checkboxes with the specified name. On the same page, multiple groups of checkboxes can be selected for the full selection. The function is sound and the versatility is strong.
:

Run to view the effect:

<Body> <script type = "text/javascript"> function checkAll (name) {var el = document. getElementsByTagName ('input'); var len = el. length; for (var I = 0; I <len; I ++) {if (el [I]. type = "checkbox") & (el [I]. name = name) {el [I]. checked = true ;}} function clearAll (name) {var el = document. getElementsByTagName ('input'); var len = el. length; for (var I = 0; I <len; I ++) {if (el [I]. type = "checkbox") & (el [I]. name = name) {el [I]. checked = false ;}} script <input type = "checkbox" name = "test" value = "" onclick = "if (this. checked = true) {checkAll ('test');} else {clearAll ('test ');} "/> enable <input type =" checkbox "name =" test "value =" a "/> a <input type =" checkbox "name =" test "value = "B"/> B <input type = "checkbox" name = "test" value = "c"/> c <input type = "checkbox" name = "test" value = "d"/> d <input type = "checkbox" name = "test" value = "e"/> e <input type = "checkbox" name = "test" value = "f"/> f <input type = "checkbox" name = "test" value = "g"/> g <br> <input type = "checkbox" name = "num "value =" "onclick =" if (this. checked = true) {checkAll ('num');} else {clearAll ('num ');} "/> number selection switch <input type =" checkbox "name =" num "value =" 1 "/> 1 <input type =" checkbox "name =" num "value = "2"/> 2 <input type = "checkbox" name = "num" value = "3"/> 3 <br> <input type = "button" value = "select all letters" onclick = "checkAll ('test ') "/> <input type =" button "value =" Clear the selected Letter "onclick =" clearAll ('test ') "/> <br> <input type =" button "value =" select all numbers "onclick =" checkAll ('num ') "/> <input type =" button "value =" Clear the selected number "onclick =" clearAll ('num') "/> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Js Functions

The Code is as follows:


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.