Click here to Skip to main content
15,915,869 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
I have a dropdown list, with an "other" item in it. When a user clicks this option, I want to enable a textbox so that users can enter details into it. Any other option should result in the textbox being disabled. Could you please tell me what I need to write to do this?
Posted
Updated 23-Mar-18 17:42pm
v2
Comments
Mahendra.p25 5-May-11 5:22am    
what do you want not clear?
Neetesh Agarwal 20-May-12 14:49pm    
If user select items from drop down list , but if he does not find desire item in list there will be another item "Other" will select by him and there will be a text box visible there user put desire value.

Quote:
if(dropdownlist.selecteditem.Text=="other")
textbox.Enabled=true;
else
textbox.Enabled=false;
 
Share this answer
 
Comments
CHill60 24-Mar-18 12:47pm    
Don't repost other member's solutions
It will work fine using java script.

XML
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem >others</asp:ListItem>
</asp:DropDownList>


XML
<asp:TextBox runat="server" ID="TextBox1" Style="display: none;">




//Download and Add this JS file in your project

http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js[^]

// NOw use this script

XML
<script type="text/javascript">
$('#<%= DropDownList1.ClientID %>').change(function () {
if (this.value == 'others') {
$('#<%= TextBox1.ClientID %>').css('display', 'block');
}
else {
$('#<%= TextBox1.ClientID %>').css('display', 'none');
}
});
</script>
 
Share this answer
 
try this code

//set AutoPostBack="true" and On selected Index Changed write that Code
protected void Dropdown1_SelectedIndexChanged(object sender, EventArgs e)
       {
           string Check = Dropdown1.SelectedItem.Text;
           if (Check == "Other")
           {
               txt.Enabled = true;
           }
           else
           {
               txt.Enabled = false;
           }
       }
 
Share this answer
 
ITS SIMPLE
C#
if(dropdownlist.selecteditem.Text=="other")
textbox.Enabled=true;
else
textbox.Enabled=false;
 
Share this answer
 
v2
Comments
Neetesh Agarwal 20-May-12 14:49pm    
but its not in java script..............
Kesha Patel 22-Feb-17 10:06am    
if i want to enable again when select other item from dropdownlist than what should i do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900