I have the following code to retrieve ids from permissions with AJAX
$('#verPermisos').click(function() {
var role = $('#roles :selected').val();
$.ajax({
type: "POST",
url: "populate",
data: { role : role },
success: function(data) {
console.log(data);
var permisoArreglo = data;
$.each(permisoArreglo, function(index, value) {
$("input:checkbox[value=" + permisoArreglo[index] + "]").attr("checked", true);
});
}
});
However I also need it to reset the checkboxes every time its clicked Ive tried
$(this).closest('form').find("input[type=checkbox]").attr('checked', false);
$('input[type=checkbox]').attr('checked', false);
I dont have any problem unchecking boxes invidually but when I use
$('input[type=checkbox]').attr('checked', false);
it no longers checks any boxes
However it hasn't worked.