Alex Rivera | Logout

jQuery - toggle select all checkboxes

Asked 2012-03-12T14:30:25.343
25

Fought with a bunch of examples and, being still new to jQuery/Javascript, cannot get my code to function (here my my template in gsp):

<table>
    <thead>
    <tr>
       <th><input type="checkbox" name="selectAll" onclick="selectAll(this.checked);"/></th>
    </tr>
    </thead>
    <tbody>
         <td>
            <td><input type="checkbox" name="domainList" value="${domainInstance.id}"/></td>
    </tbody>
<table>

I have the following javascript snippet in my main gsp, that calls the template:

function selectAll(status) {

}

How do I select all checkboxes from the selectAll name?

Edit
Report

1 Answer

2

to select all checkboxes with name = selectAll and set their status you can do

function selectAll(status) {
   $('input[name=selectAll]').each(function(){
      $(this).prop('checked', status);
   });
}
answered 2012-03-12T14:34:15.623

Your Answer