I have the checkboxes and its values are populated from the database. I can select and deselect all the checkbox but I am not able to get the values of individual checked checkbox. This is what I have done so far, for the checkbox populating from database:
<form>
<br>
<input type="checkbox" id="All"> <b>Select/DeSelect All</b><br>
<?php
$sql = 'SELECT Subject_Category from {extdb_subjects} where level=1 ';
$res = db_query($sql);
foreach ($res as $row)
{
echo "<input type='checkbox' id='sub_names' name='{$row->Subject_Category}'
value='{$row->Subject_Category}'";
echo ">{$row->Subject_Category}";
echo "<br>";
}
?>
</form>
JQuery script for selecting de selecting all the check box and individual display of the checked checkbox:
jQuery(function(){
jQuery('#All').change(function() {
var checkboxes = jQuery(this).closest('form').find(':checkbox');
if(jQuery(this).is(':checked')) {
checkboxes.attr('checked', 'checked');
} else {
checkboxes.removeAttr('checked');
}
});
jQuery('#sub_names').change(function() { //This is not able to get the values
if(jQuery(this).is(':checked')) {
alert(jQuery("input[type=checkbox]:checked").val());
}
});
});
Any suggestions will be highly appreciated.