Javascript for disabling dropdown in ASP.NET
- by Lijo
Hi Team,
I am using JScript in ASP.NET 2005. I have a page with a checkbox and a dropdown list. When the checkbox is checked the dropdown is to be disabled. During Postback of the page this should be retained. I am using a javascript function as follows
if((chkOwner[1].checked==true))
{
document.getElementById(ddlClientID).disabled=true;
document.getElementById(ddlClientID).className = "form-disabled";
document.getElementById(ddlClientID).selectedIndex = 0;
}
else
{
document.getElementById(ddlClientID).disabled=false;
document.getElementById(ddlClientID).className = "form-input";
document.getElementById(ddlClientID).selectedIndex = 0;
}
This works, almost. However, the dropdown selection is not retained after postback (when checkbox is not selected).
Apprently the solution is to remove the last line, i.e, in the else part, remove the selectedIndex =0 setting.
But, when I do that the disabling of dropdown (when check box is selected) is not working after post back.
Could you please help on this?
Thanks
Lijo