How would i be able to disable the rest of the checkboxes once the selected items is 5? I was thinking there could be a way to do this in jquery. Here is my code below.
<table>
@{ var i = 0;}
@foreach (var testimonials in Model.Testimonials)
{
<tr>
<td style="padding: 2px 0 2px 2px;">
@Html.CheckBox("Testimonials[" + i.ToString() + "].DisplayTestimonials", testimonials.DisplayTestimonials.Value, new { @class = "chkItems" })
@Html.Hidden("Testimonials[" + i.ToString() + "].ResponseId", testimonials.ResponseId.ToString())
</td>
<td style="padding: 2px 0 2px 2px;">@Html.TextBox("Testimonials[" + i.ToString() + "].FirstName", testimonials.FirstName, new { @readonly = "readonly", @class = "TextBoxAsLabel" })</td>
<td style="padding: 2px 0 2px 2px;">@Html.TextBox("Testimonials[" + i.ToString() + "].LastName", testimonials.LastName, new { @readonly = "readonly", @class = "TextBoxAsLabel" })</td>
<td style="padding: 2px 0 2px 2px;">@Html.TextBox("Testimonials[" + i.ToString() + "].Question5Answer", testimonials.Question5Answer.ToString(), new { @readonly = "readonly", @class = "TextBoxAsLabel" })</td>
</tr>
i++;
}
Solution:
<script type="text/javascript">
$(document).ready(function () {
function countchecked() {
var n = $("input:checked").length;
if (n >= 5)
$('.chkItems:not(:checked)').attr("disabled", "disabled");
else
$('.chkItems:not(:checked)').removeAttr("disabled");
}
$(":checkbox").click(countchecked);
});