I have a GridView on a webpage containing a Textbox and a CheckBox. I want the Textbox to be enabled when the CheckBox is checked, and disabled when it is unchecked using pure javascript.
Can anyone help me solve this issue? Thank you in advance.
<asp:GridView ID="grdBasicApproval" runat="server" AutoGenerateColumns="false" Width="90%"
CssClass="mGrid" DataKeyNames="EmpId">
<Columns>
<asp:TemplateField Visible="true" HeaderText="Remark">
<ItemTemplate>
<asp:TextBox ID="txtRemark" runat="server" Width="125px" TextMode="MultiLine" Style="resize: none"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="7%">
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" Text="All" onclick="CheckAll(this);"
TextAlign="Left" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild" runat="server" onclick="return Check_Click(this);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is my JavaScript code:
$(document).ready(function () {
try {
$("input[type=checkbox][id*=chkChild]").click(function () {
if (this.checked) {
alert("Checked");
$(this).closest("tr", "").find("input[type=TextBox][id*=txtRemark]").attr("disabled", true);
}
else {
alert("UnChecked");
$(this).closest("tr", "").find("input[type=TextBox][id*=txtRemark]").attr("disabled", true);
}
});
} catch (e) {
alert(e);
}
});