Reputation: 4845
I have a list view and its contain n number of check box. I want to do enable/disable when clicking the first checkbox. i have written a code in jquery. But its taking all the check box in the page. I need to enable / disable only the selected row.
function EnableCurrentRowControls(chkID)
{
var chkBox = document.getElementById(chkID);
var chkIDList = document.getElementsByTagName("input");
for (i = 0; i < chkIDList.length; i++)
{
if (chkIDList[i].type == "checkbox" && chkIDList[i].id != chkBox.id) {
if (chkIDList[i].type == "checkbox" && chkIDList[i].id != chkBox.id)
{
chkIDList[i].enabled = false;
}
}
}
}
Calling function in ListView Control
<asp:CheckBox ID="chkUserBoardMaping" OnClick="javascript:EnableCurrentRowControls(this.id)"
runat="server" />
Pls have a look and advice me..
Upvotes: 0
Views: 702
Reputation: 672
May be trying with something like this:
function EnableCurrentRowControls(element) {
if ($(element).closest('tr').find('input[type=checkbox][id*=chkUserBoardMaping]').is(':checked')) {
$(element).closest('tr').find('input[type=text][id*=myTextBox]').removeAttr("disabled");
}
else {
$(element).closest('tr').find('input[type=text][id*=myTextBox]').prop("disabled");
}
}
You'll also have to change this (1. pass only this as an argument 2. change onclick event to onchange) :
<asp:CheckBox ID="chkUserBoardMaping" onchange="javascript:EnableCurrentRowControls(this)"
runat="server" />
Be sure that you changed control (myTextBox) name!
Upvotes: 1