Set other checkbox value & name when checkbox checked
Your closest needs to go further
$(".loc").on("change", function() {
const $nextDD = this.closest("dd").next();
if ($nextDD) {
const $withoutqr = $nextDD.find(".without-qr");
if (this.checked) {
$withoutqr.val(0);
$withoutqr.attr('name', 'qr[]');
} else {
$withoutqr.removeAttr("name");
}
}
});
please try this and change the closest function value for finding next block HTML
$(".loc").change(function() {
if($(this).is(':checked')) {
$(this).closest('dd').next().find('.without-qr').val(0);
$(this).closest('dd').next().find('.without-qr').attr('name', 'qr[]');
}else{
$(this).closest('dd').next().find('.without-qr').removeAttr("name");
}
});