it make strange action not checked meaning some behaviour affect on check box so it checked but quickly after less than second it not checked why <button id="FillCheckBox" type="submit" class="col-sm-1 btn btn-primary">Submit</button>
The issue might relate the submit button, since the type is submit
, by default after clicking the submit type button, it will directly submit the form. But from your code, you might just want to call the handle method and change the checkbox status, so there is no need to submit the form.
To solve this issue, try to change the button type from submit
to button
.
<button id="FillCheckBox" type="button" class="col-sm-1 btn btn-primary">Submit</button>
Or you can disable the submit button default behavior in its button click event:
$('#FillCheckBox').click(function () {
event.preventDefault();
$.ajax({
url: '/AddUserAccess?handler=RelatedUserAccessPermission',
data: { UserId: $('#useraccess-id').val() }
}).done(function(r) {
$('#StockTake,#ShelfLabelPrint,#Transfer').each(function() {
this.checked = r.findIndex(e => e.ModuleCode == this.value) >= 0;
});
}).fail(function(jqXHR, textStatus, errorThrown) {
alert("ajax call failed");
});
});
Note: If using the above methods, there should have two buttons in the page, one for the checkbox and another is used to submit the form. Or you can change the checkbox status after page load, instead of using the submit button click event.
Best regards,
Dillion