I made the code to disable the control when the user clicks on the control. In my form I have TextBoxand DropDown. When the user clicks on TextBoxI will disable DropDown, as when clicking on DropDown, I disconnect TextBox, which works fine.
But when the user clicks on the control Disabled, I would like to enable this control. So if I click on TextBoxwhich was disabled, I would like Enableto do it for DropDowntoo ..
My example script is as follows
<script type="text/javascript">
function toggleDropDownList1()
{
var d=document.getElementById("<%= DropDownList4.ClientID %>");
if(d.disabled)
{
d.disabled=false;
}
else
{
document.getElementById("<%= TextBox1.ClientID %>").disabled = true;
}
}
function toggleDropDownList2()
{
document.getElementById("<%= DropDownList4.ClientID %>").disabled = true;
}
</script>
Design
<asp:TextBox ID="TextBox1" runat="server" onclick="toggleDropDownList2();"></asp:TextBox>
<asp:DropDownList ID="DropDownList4" runat="server" onclick="toggleDropDownList1();">
<asp:ListItem Text="One" Value="1"></asp:ListItem>
<asp:ListItem Text="One" Value="1"></asp:ListItem>
</asp:DropDownList>
source
share