I have multiple columns that are being displayed on the page. I wanted to add check boxes so the specified row can be edited based on selection. However there is a problem, because I am not able to edit the box that is checked.
For instance:
box | ID | Date
checked | 1 | 11/20/18 <-- this should be editable
unchecked | 2 | 11/15/18 <-- this should just be displayed
JavaScript / Jquery:
$(".id").on('click', function (e) {
var key = "#date-" + e.target.id;
var check = "#" + e.target.id;
if ($(check).attr(':checked')) {
$(key).removeAttr("readonly", false);
$(key).focus();
} else {
$(key).attr("readonly", "readonly");
}
});
HTML:
@foreach (var item in Model)
{
<td><input class="id" type="checkbox" id=@item.ID/></td>
<td>@Html.DisplayFor(x => item.ID)</td>
<td><input id='@item.ID' type="text" value='@item.Date' readonly="readonly" /></td>
}
Any help would be appreciated!