I have a list of checkboxes in a table like this along with a button:-
<table id="mytable">
<tr><th>checked</th><th>id</th><th>text</th></tr>
<tr><td><input id="cb1" type="checkbox" name="checker1"/></td><td>123</td><td>abc</td></tr>
<tr><td><input id="cb2" type="checkbox" name="checker2"/></td><td>456</td><td>def</td></tr>
<tr><td><input id="cb3" type="checkbox" name="checker3"/></td><td>789</td><td>ghi</td></tr>
<tr><td><input id="cb4" type="checkbox" name="checker4"/></td><td>454</td><td>ghi</td></tr>
<tr><td><input id="cb5" type="checkbox" name="checker5"/></td><td>565</td><td>ghi</td></tr>
</table>
<input type="button" name="myjqbutton" value="My Jquery Button" id="jqb" disabled="true"/>
What i want to do is, only enable the button if 1 or more checkboxes are checked.
Initial thoughts are that I need to count the amount of checkboxes checked in the table, I can do this using a .each to count them into a variable.
var mytable= document.getElementById('mytable');
$('input:checkbox:checked', mytable).each(function() {
// whatever here
});
However, each checkbox will need a changed event to check the count and enable or disable the button depending if count > 0 or not.
Or is there an easier way of achieving this functionality I am looking for.
You could do