I'm trying to access the data attribute of a checkbox to pass through to a PHP script to update my database.
The HTML looks like this:
<input type="checkbox" data-entid="1"onchange="updateOrDeleteEntitlements()"
checked>
The jQuery function is:
function updateOrDeleteEntitlements() {
var role = $('#selectedRole').val();
var ent = $(this).data('entid');
var binMe = '';
$.ajax({
url: 'ajax/update_delete_entitlements.php',
type: 'post',
data: {'role': $role, 'ent': ent, 'delete': $binMe},
success: function(data) {
console.log(data);
}
});
}
The line var ent = $(this).data('entid');
should be storing the data held in the checkbox so I can pass it through in my AJAX but is returning undefined.
Spent around an hour trying some slightly different things but nothing seems to work. I've also used this same exact thing elsewhere in my code (but pulling data from a tr rather than input) so I'm completely beffudled.
Any help is much appreciated