Click here to Skip to main content
14,455,062 members
Rate this:
Please Sign up or sign in to vote.
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 18: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.
Rate this:
Please Sign up or sign in to vote.

Solution 4

It will work fine using java script.

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


<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

<script type="text/javascript">
$('#<%= DropDownList1.ClientID %>').change(function () {
if (this.value == 'others') {
$('#<%= TextBox1.ClientID %>').css('display', 'block');
}
else {
$('#<%= TextBox1.ClientID %>').css('display', 'none');
}
});
</script>
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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;
           }
       }
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

ITS SIMPLE
if(dropdownlist.selecteditem.Text=="other")
textbox.Enabled=true;
else
textbox.Enabled=false;
   
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?
Rate this:
Please Sign up or sign in to vote.

Solution 6

Quote:
if(dropdownlist.selecteditem.Text=="other")
textbox.Enabled=true;
else
textbox.Enabled=false;
   
Comments
CHill60 24-Mar-18 12:47pm
   
Don't repost other member's solutions

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100