I'm using mvc, I need to change the "readonly" and "disabled" attributes of element Html.CheckBoxFor
. I'm using a JavaScript for that:
function ReadOnlyHandle() {
var Collection = document.getElementsByClassName("SubjectCB");
debugger;
for (var i = 0; i < Collection.length; i++)
{
Collection.item(i)..("disabled", "disabled");
Collection.removeAttribute("readonly", "readonly");
}
debugger;
}
I'm trying to get the collection of checkboxes (since I have few) and then iterate them to change their attributes.
@for (int i = 0; i < Model.Topics.Count(); i++)
{
<tr id="row-@i">
<td>@Html.LabelFor(t => t.Topics[i].Box.Selected, Model.Topics[i].Box.Text)</td>
<td class="SubjectCB">@Html.CheckBoxFor(t => t.Topics[i].Box.Selected, new { @checked = "checked", @readonly = "readonly", @disabled = "disabled" })</td>
<td class="IsReadOnly">@Html.TextBoxFor(model => model.Topics[i].NumberOfNoDifficulltySet, new { @readonly = "readonly" })</td>
<td class="IsReadOnly">@Html.TextBoxFor(model => model.Topics[i].NumberOfEasy, new { @readonly = "readonly" })</td>
<td class="IsReadOnly">@Html.TextBoxFor(model => model.Topics[i].NumberOfMedium, new { @readonly = "readonly" })</td>
<td class="IsReadOnly">@Html.TextBoxFor(model => model.Topics[i].NumberOfHard, new { @readonly = "read" })</td>
</tr>
}
Yet, in the collection, the variable defined in Javascript does not have the "removeAttribute" function - why is that? Or can I change the attributes another way?