javascript to check/uncheck all checkboxes

1 var Checkboxes = {
2    /**
3   * checks all the checkboxes of a given class name
4   */
5    checkAll: function(className) {
6    Checkboxes.setChecking(className, true);
7 },
8
9    /**
10   * unchecks all the checkboxes of a given class name
11   */
12    uncheckAll: function(className) {
13    Checkboxes.setChecking(className, false);
14    },
15
16      /**
17   * toggles the value of the checkboxes of a given class name
18   */
19    toggle: function(className) {
20    Checkboxes.setChecking(className, toggle‘);
21   },
22
23   /**
24   * sets the checked value of elements of a given class name
25   */
26   setChecking: function(className, value) {
27   var boxes = document.getElementsByClassName(className);
28   var cur_value = false;
29   for (var i=0, boxes_len=boxes.length; i<boxes_len; i++) {
30     if (value == toggle‘) {
31       cur_value = boxes[i].checked;
32       if (cur_value == true) {
33           boxes[i].checked = ‘;
34         } else {
35           boxes[i].checked = checked‘;
36         }
37       } else {
38           boxes[i].checked = value;
39       }
40     }
41   }
42 }
This entry was posted in Programming. Bookmark the permalink.