Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to show or hide textbox based on drop down list selected value.

When selected value will be "Other" then textbox will be visible.

Here is my javascript code:

$("#gridhvac input[name$='ddlhvacmake_rev']").change(function () {
           if (this.value == "Other") {
               $("#gridhvac input[name$='txtother_rev']").attr("style","display: block;");
           }
           else {
               $("#gridhvac input[name$='txtother_rev']").attr("style", "display: none;");
           }
       });


and here is aspx code:

<asp:TemplateField HeaderText="MAKE">
        <EditItemTemplate>
        <asp:DropDownList ID="ddlhvacmake" runat="server">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
        <asp:ListItem>Other</asp:ListItem>
        </asp:DropDownList>
<br />
        <asp:TextBox runat="server" ID="txtother" Style="display: none;"/>
        
        </EditItemTemplate>
        <ItemTemplate>
        <asp:Label ID="lblhvacmake" runat="server" Text='<%#Eval("MAKE") %>'/>
        </ItemTemplate>
     <FooterTemplate>
                <asp:DropDownList ID="ddlhvacmake_rev" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>Other</asp:ListItem>
                </asp:DropDownList>
                <br />
                <asp:TextBox runat="server" ID="txtother_rev" Style="display: none;"/>
            </FooterTemplate>
        
        </asp:TemplateField>


I cannot figure out what's wrong in this code. This does not work and there is no error also.
Posted
Comments
Andy Lanng 16-Sep-15 4:03am    
Have you stepped through the javascript? I use chrome but firebug for firefox isn't bad. You can set breakpoints and check the values of your variables. That might help you find the issue
planetz 16-Sep-15 5:43am    
I'll follow your suggestion Andy...
planetz 16-Sep-15 6:34am    
Well it says object expected...any idea what object can be missing??

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