Hide and show textbox based on dropdown value

Hide and show textbox based on dropdown value

HI,

I have a dropdownlist and a textbox (few other controls and button) in my aspx page. If the dropdownlist has value as "Other", then I want to show the textbox.

On postbacks of other events, the textbox is getting shown. By default, on loading the textbox should be hidden and only when dropdown has value of "Other", then textbox should be shown.

  1. I have tried this code, but it does not work on postbacks:
     
     
    $(document).ready(function () {
       
            $(function () {
                $('#<%=txtEntityOther.ClientID%>').hide();
                $('#<%=ddlEntity.ClientID%>').change(function () {
                    var val = $(this).find(":selected").text();
                   if (val == "Other") {
                        $('#<%=txtEntityOther.ClientID%>').show();
                    }
                });
            });
        });
 
How to fix this