Reputation: 575
My submit.cshtml
is:
<table id="scDetails" class="table">
<thead>
<tr>
<th>Item</th>
<th>IsChecked</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
@Html.EditorFor(m => m.Fbacks)
</tbody>
</table>
EditorTemplate is for - @Html.EditorFor(m => m.Fbacks)
(Fbacks.cshtml)
<tr>
<td>@Html.HiddenFor(m => m.Item)
@Html.DisplayFor(m => m.Item)
</td>
<td>@Html.CheckBoxFor(m => m.IsChecked)</td>
<td>@Html.TextBoxFor(m => m.Comment)</td>
</tr>
What I need is:
When I check the checkbox, textbox should be enabled and when uncheck, textbox should disabled.
Upvotes: 0
Views: 1842
Reputation: 55740
$('input[type=checkbox]').on('click', function() {
var isChecked = $(this).is(':checked');
$(this).parent().next().find('input[type="text"]').attr('disabled', !isChecked);
});
// OR
$('input[type=checkbox]').on('click', function() {
var isChecked = $(this).is(':checked');
$(this).parent().parent().find('input[type="text"]').attr('disabled', !isChecked);
});
Upvotes: 1
Reputation: 490173
$("input[type='checkbox']").on("click", function() {
$(this).parent().next().find("textarea").prop("disabled", ! this.checked);
});
Upvotes: 2
Reputation: 2251
You should add event to checkbox
$('#Fbacks').click (function ()
{
var thisCheck = $(this);
if (thischeck.is (':checked'))
{
$('#Comment').prop('disabled', true);
}else{
$('#Comment').prop('disabled', false);
}
});
in this case @Html.EditorFor(m => m.Fbacks)
id = 'Fbacks'
Upvotes: 1