I want to get the value of the checkbox that goes from being checked to unchecked.
<input type="checkbox" class="cbx" name="privilegiosG[]" id="privilegioG_<?= $privilegio->getId() ?>" value="<?= $privilegio->getId() ?>" <?= $checked; ?> />
tried this but it doesn’t work for me
<script type="text/javascript>"
$("input[name='seccionesG'] input:checkbox").change(function() {
var ischecked= $(this).is(":checked");
if(!ischecked)
alert("uncheckd " + $(this).val());
});
</script>
2
Answers
The code looks quite complicated for a simple task, this should work:
This is because of incorrect selector:
input[name='seccionesG'] input:checkbox
.It’s invalid, it’s means: find an input with name
seccionesG
, then inside it look for all inputs which are checkboxes.You can test it quickly by making a selector which will work for all checkboxes:
Now, since your input name is
privilegiosG[]
then your selector should be:Note that you have a name with square brackets, which has a special meaning. For this reason you will need to add quotes to make it work. If you want to know more check jQuery selector for inputs with square brackets in the name attribute.