I know there are lot of examples here that shows how to count the checked checkboxes but for some reason I'm unable to make this work.
What I'm trying to do is that when at least one checkbox in my page is checked a button should be enable or disable if none of the checkboxes are checked.
The thing is even that I implemented the following code, the count of checked checkboxes is always 0, I'm not sure what I'm missing.
Primefaces component:
<p:column id="idSelectBox" selectionMode="multiple" style="width:68px" />
JQuery Code:
function countChecked() {
var n = $("input:checkbox:checked").length;
alert('Count: ' + n);
}
$(":checkbox").click(countChecked);
Hope you can help me out!
UPDATE 1:
I did a little more research and the Primefaces component does not render to HTML checkboxes elements, its outputs is a set of divs and classes:
<td class="ui-selection-column">
<div class="ui-dt-c">
<div class="ui-radiobutton ui-widget">
<div class="ui-radiobutton-box ui-widget ui-corner-all ui-radiobutton-relative ui-state-default">
<span class="ui-radiobutton-icon"></span>
</div>
</div>
</div>
</td>
So I'm still trying to figure out how I can detect whether the checkbox was checked or not.