PDA

View Full Version : CheckBoxList in JavaScript Problem


asifakhtar
03-14-2009, 08:03 PM
I have an asp:CheckBoxList named cblRoles with values. The values are coming from the database and can be in any order in cblRoles. When I check enabled “Admin” option from cblRoles my JavaScript function CheckAdmin’s IF STATEMENT works but when I check enabled “Admin” option from cblRoles and make “Admin” option DISABLE, listControl.checked in the IF STATEMENT FAILS
Here is my complete JavaScript code:function CheckAdmin(source, args)
{
args.IsValid = false;
var cblRoles = document.getElementById('<%= cblRoles.ClientID %>');
var num = cblRoles.childNodes[0].childNodes.length;
var currentTable = cblRoles.childNodes[0];

for (var i=0 ; i<num ; i++)
{ var InnetText = currentTable.childNodes[i].childNodes[0].innerText;
var currentTd = currentTable.childNodes[i].childNodes[0];
var listControl = currentTd.childNodes[0];
if (InnetText=="Admin" && listControl.checked)
{
args.IsValid = true; return;
}
}
}

Here I am posting my generated SOURCE code

<tr>
<td><span disabled="disabled"><input id="ctl00_ContentPlaceHolder1_cblRoles_0" type="checkbox" name="ctl00$ContentPlaceHolder1$cblRoles$0" checked="checked" disabled="disabled" /><label for="ctl00_ContentPlaceHolder1_cblRoles_0">Admin</label></span>

</td>
</tr>

<tr>
<td><input id="ctl00_ContentPlaceHolder1_cblRoles_1" type="checkbox" name="ctl00$ContentPlaceHolder1$cblRoles$1" /><label for="ctl00_ContentPlaceHolder1_cblRoles_1">Electrichain</label>

</td>
</tr>

<tr>
<td><input id="ctl00_ContentPlaceHolder1_cblRoles_2" type="checkbox" name="ctl00$ContentPlaceHolder1$cblRoles$2" /><label for="ctl00_ContentPlaceHolder1_cblRoles_2">Painter</label>

</td>
</tr>

<tr><td><input id="ctl00_ContentPlaceHolder1_cblRoles_3" type="checkbox" name="ctl00$ContentPlaceHolder1$cblRoles$3" /><label for="ctl00_ContentPlaceHolder1_cblRoles_3">Tenant</label></td>
</tr>