In my html page I want to dynamically insert checkboxes, and I want to have 1 master checkbox on top, so if that is checked, then all the dynamically created ones become checked, and if it is unchecked, then all dynamically ones become unchecked. I have this code:
<script type="text/javascript">
$(function() {
$("#selectAll").click(function() {
var checked = $(this).prop('checked');
$(".profilebox").attr("checked", checked);
});
});
</script>
master check box
<input id="selectAll" type="checkbox" name="selectall" value="All">
other checkboxes: (gets inserted in a loop using this php code)
<input type='checkbox' class='profilebox' name='select' value='{$member_id}'>
However it is not functioning properly. If I click the master one, then they all get checked. If I click it again, then all get unchecked, then if I click it again, they all still remain unchecked.
Does anyone know the problem?
Thanks