I have the following code which produces a list of checkboxes. This list could contain any amount of checkboxes and will vary per record:
@if (Model.PaymentRefundData != null)
{
for (int i = 0; i < Model.PaymentRefundData.Count(); i++)
{
<tr>
<td>
@Html.HiddenFor(j => j.PaymentRefundData[i].ContractContributionHistoryId)
@Html.DisplayFor(j => j.PaymentRefundData[i].CommencementDeductions)
</td>
<td>
@Html.DisplayFor(j => j.PaymentRefundData[i].Category)
</td>
<td>
@Html.DisplayFor(j => j.PaymentRefundData[i].NumberOfContributions)
</td>
<td>
@Html.DisplayFor(j => j.PaymentRefundData[i].EmployeeContributionReference)
</td>
<td>
@Html.DisplayFor(j => j.PaymentRefundData[i].TeamMemberName)
</td>
<td>
@Html.CheckBoxFor(j => j.PaymentRefundData[i].NotInUse, new { id= "checked" })
</td>
</tr>
}
}
I also have this code to disable a checkbox, when it has been checked. The problem is that it will only disable the first checkbox, I need to disable any in the list:
$(document).on('click', '#checked', function () {
if ($("#checked").prop('checked', true)) {
$('#checked').attr('disabled', true);
}
});
Thanks
Thanks to Rory & Tokunbo, both these solutions do exactly what I ask, however having implemented them, I realise that it's not going to work for me as a disabled checkbox doesn't post when I hit save.
I am now thinking that the best way to handle this it to make any checked checkboxes disabled on page load, as when I hit save, the page will reload. Again I am having problems though, this code achieves the disabled part, however the issue is that it's automatically setting all checkboxes to checked:
$(document).ready( function () {
if ($(".checked").prop('checked', true)) {
$('.checked').attr('disabled', true);
}
});