Wednesday, August 18, 2010

Code for Select and deselect all check boxes in javascript.?

I have to select and deselect a check box column in a datagrid. When i click the header check box all the checkboxes in the column should be checked and vice-versa for uncheck also. But if we uncheck a single check box after checking all checkboxes , the header check box should also be unchecked. Sorry for confusing like this. Because my English is Somewhat bad. Anybody pls send me sample code for this and how to call the javascript function in HTML.Code for Select and deselect all check boxes in javascript.?
Here's part of it. This function checks all the checkboxes for recruits in the list.





function chkAll_Click() {


var checked = document.getElementById ('chkAll').checked;





for (i = 0; i %26lt; document.forms[0]. recruits.length; i++) {


document.forms[0]. recruits[i].checked = checked;


}


}





The javascript function in my case is actually set up as the 'on_click' event in the header template:





%26lt;input type=';checkbox'; id=';chkAll'; name=';chkAll'; onclick=';chkAll_Click();'; /%26gt;





Watch out for extra spaces I put in to make the code fit here.





hope that helps you out

No comments:

Post a Comment