Javascript check and uncheck all checkboxes

Source: Internet
Author: User
Javascript check and uncheck all checkboxes
By nannette Thacker-04/27/2000

6/7/01 Update: Please see a response to a letter on this article for further details on how to check if there is only one checkbox in a set. (for instance, if you are building your set from a table and don't know if there is more than one checkbox in the set or not .) letters

By passing the checkbox group's name to the onclick event of the buttons, you can check and uncheck all checkboxes dynamically. you don't need to hard code the name of the checkbox or know the number of check boxes in the group. the Code takes care of this automatically.

Here is the javascript:

<Script language = "JavaScript"> <! -- // By nannette Thacker // http://www.shiningstar.net // This script checks and unchecks boxes on a form // checks and unchecks unlimited number in the group... // pass the checkbox group name... // call buttons as so: // <input type = button name = "checkall" value = "check all" // onclick = "checkall (document. myform. list) "> // <input type = button name =" uncheckall "value =" uncheck all "// onclick =" uncheckall (token en T. myform. List) "> // --> <! -- Beginfunction checkall (field) {for (I = 0; I <field. length; I ++) Field [I]. checked = true;} function uncheckall (field) {for (I = 0; I <field. length; I ++) Field [I]. checked = false;} // end --> </SCRIPT>
 
 

Here is the HTML:

<Form name = "myform" Action = "checkboxes. ASP "method =" Post "> <B> your favorite scripts & ages </B> <br> <input type =" checkbox "name =" list "value =" 1"> JAVA <br> <input type = "checkbox" name = "list" value = "2"> JavaScript <br> <input type = "checkbox" name = "list" Value = "3"> Active Server Pages <br> <input type = "checkbox" name = "list" value = "4"> HTML <br> <input type = "checkbox" name = "list" value = "5"> SQL <br> <input type = "button" name = "checkall" value = "check all" onclick = "checkall (document. myform. list) "> <input type =" button "name =" uncheckall "value =" uncheck all "onclick =" uncheckall (document. myform. list) "> <br> </form>
 
 

Check out the JavaScript source for some of the best possible cripts!

check out this cool RGB/Hex converter chart! Http://javascript.internet.com/calculators/rgb-slider.html

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.