I have a function for select/check all checkbox that id=hap
$(function () {
$('#select-all').click(function (event) {
var selected = this.checked;
$('#hap').each(function () { this.checked = selected; });
});
});
This is my checkbox to select all.
<input type='checkbox' id='select-all'><label for='select-all'>Delete all</label>
And I use it for select data that I've fetched by php
$data=mysql_query("SELECT*FROM comment where news_id='$id'");
$x=0;
while($a=mysql_fetch_array($data)){
$x++;
echo"
<td class='center'>
<input id='hap' type='checkbox' name='c_$x' value='$a[comment_id]'>
</td>";
}
But it just select/check one data in the first loop, another data isn't selected.
Anyone know what's wrong with it?