08 April 2009
0 To check the select-all checkbox in a page when all other checkboxes in the page is checked
On click of any of the checkboxes other than the select-all checkbox call the function checkFunction. This function checks if all the other checkboxes with name checkItem is checked or not. If all the checkboxes with name checkItem is checked the select-all is checked. If any of the checkboxes with name checkItem is unchecked then the select-all checkbox will be unchecked.
// call this function when the any of the checkbox other than the selectall checkbox is clicked function checkFunction(){ var count =0; var check = document.getElementsByName("checkAll"); var innerCheck = document.getElementsByName("checkItem"); for (var i=0; i<innerCheck.length; i++) { if(innerCheck[i].checked ==true){ count = count +1; } } if (count == innerCheck.length){ for (var i=0; i<check.length; i++) { check[i].checked = true; } } for (var i=0; i<check.length; i++) { if(check[i].checked == true){ for (var j=0; j<innerCheck.length; j++) { if(innerCheck[j].checked ==false){ check[i].checked = false; } } } } } - checkAll is the name of the select all checkbox - checkItem is the name of the other checkboxes |
0 comments:
Please give your valuable comments.