08 April 2009

0 To check all checkbox when select-all is checked or to deselect all when select-all is unchecked

Here is the JavaScript code snippet for checking all checkbox when select-all is checked or to deselect all when select-all is unchecked


// to check whether select-all(Select All) check-box is checked or not

// call this function when the select-all(Select All)checkbox is clicked

function checkAll() {

var check = document.getElementsByName("checkAll");

if(check[0].checked==true){

selectAll(check);

}

else {

deSelectAll(check);

}

}

// to select all the check-boxes

function selectAll(check){

var check2 = document.getElementsByName("checkItem");

for (var i=0; i<check2.length; i++) {

check2[i].checked=true;

}

}

// to de-select all the check-boxes

function deSelectAll(check){

var check2 = document.getElementsByName("checkItem");

for (var i=0; i<check2.length; i++) {

check2[i].checked=false;

}

}



- checkAll is the name of the select-all checkbox
- checkItem is the name of the other checkboxes




0 comments:

Feeds Comments

Please give your valuable comments.