I created a code that disables a control when the user clicks on it. On my form, there is a TextBox
and a DropDown
. When the user clicks on the TextBox
, I disable the DropDown
, and vice versa.
However, if the user clicks on a disabled control, I want to enable it. For example, if the user clicks on a disabled TextBox
, I want to enable it, and the same goes for the DropDown
.
This is an example of my script:
<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="Two" Value="2"></asp:ListItem>
</asp:DropDownList>