I made a bad attempt and it sort of working until there are more than 10 items.. I just take the name of the associated textbox and try to match it up with the checkbox but it is ugly..Someone have a proper way to do this ?
$('.naCheckbox').click(function () {
var $this = $(this);
var checkboxId = $this.attr("id");
var textboxId = checkboxId.slice(0, 16) + "ProfileAnswerText";
if ($this.is(':checked')) {
$('#' + textboxId).attr("disabled", "disabled")
} else {
$('#' + textboxId).removeAttr("disabled");
}
});
<div id="tabs-1" class="tabTwo">
@for (var i = 0; i < Model.ProfileItems.Count(); i++)
{
<div class="question-block">
<p> @Html.HiddenFor(m => m.ProfileItems[i].ProfileFieldId)</p>
<p class="questions"> @Model.ProfileItems[i].ProfileQuestionText </p>
@if (Model.ProfileItems[i].NotApp == true)
{
@Html.TextAreaFor(m => m.ProfileItems[i].ProfileAnswerText, new { disabled = "disabled", @class = "autofit" })
}
else
{
@Html.TextAreaFor(m => m.ProfileItems[i].ProfileAnswerText, new { @class = "autofit" })
}
<label style="float: right; text-align:unset; width:220px;">
N/A
@Html.CheckBoxFor(m => m.ProfileItems[i].NotApp, new { @class = "naCheckbox" })
</label>
</div>
}
</div>