Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I have a list of items in my dropdown list.
Iam inserting data of items in database based on selection in dropdownlist.
for example i have six text boxes in my page ,if i select random items in dropdownlist i want to hide some text boxes
Posted
Comments
ridoy 29-Dec-14 6:50am    
Do you try something?

It should be an easy task unless there are more conditions.

You may code like -

C# Approach

On dropdownlist SelectedIndexChanged
(Make sure that you have set property AutoPostBack="True" for that dropdownlist)

C#
If(drp.SelectedValue=="first")
{
   txt1.Visible=false;
   txt2.Visible=true;
   //... and son on
}
else if(drp.SelectedValue=="second")
{
  txt2.Visible=false;
  txt1.Visible=true;
  //... and so on
}


Javascript Approach
aspx snippet
ASP.NET
<asp:DropDownList  ID="drp" runat="server" onchange="HideTextBoxes();"


Javascript snippet
JavaScript
<script>

function HideTextBoxes()
        {
             var selectedvalue= document.getElementById("<%=drp.ClientID%>").value;
           
             if(selectedvalue == "first")
             {
                 document.getElementById("<%=txt1.ClientID%>").style.display = 'none';
                 document.getElementById("<%=txt2.ClientID%>").style.display = '';//....and son....
              
             }
             else if(selectedvalue == "second")
             {
                document.getElementById("<%=txt2.ClientID%>").style.display = 'none';
                document.getElementById("<%=txt1.ClientID%>").style.display = '';// ... and son on
               
             }
        }

 </script>
 
Share this answer
 
v3
Comments
ridoy 29-Dec-14 6:50am    
5ed!
try this...
XML
<select name="type">
  <option value="plane">Plane</option>
  <option value="car">Car</option>
</select>
<input class="hideme" type="text" name="name">



JavaScript
$('select').change(function(){
if($(this).val()=== "car")
$('.hideme').show();
else
    $('.hideme').hide();
}).change();
 
Share this answer
 
You need to search well before posting such questions. See:
Enable/disable textbox based on dropdown selection.[^]
 
Share this answer
 
Comments
ridoy 29-Dec-14 7:23am    
Whoa! some downvoters find it interesting to downvote without complaining anything! Cheers guys!

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