Check box select all script for table


I haven’t had a lot of luck finding the javascript code snippet by which I want to select all the rows in a table when I click on the header check box. Can any one lead me to the source or show me the code for it?