Click here to Skip to main content
15,886,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I written code for getting textbox visible true dynamically using javascript

I am getting the textbox when i select 'others' in dropdown

when there is postback the textbox disappears

How to display the textbox with values after postback
below is my source code



HTML
        function ddlChanged(ddl) {
            if (ddl.value == "4") {
                document.getElementById('<%=txt_reason.ClientID %>').removeAttribute("disabled");               
                document.getElementById('<%=div_otherreason.ClientID %>').style.visibility='visible';
                document.getElementById('<%=div_otherreason.ClientID %>').style.display = 'block';
            }
            else {
                document.getElementById('<%=txt_reason.ClientID %>').setAttribute("disabled", true);
                document.getElementById('<%=txt_reason.ClientID %>').value = '';
                document.getElementById('<%=div_otherreason.ClientID %>').style.visibility='hidden';                
            }
        }
        ddlChanged(document.getElementById('<%=ddlReason.ClientID %>'));
    


<div class="col-md-4">
                                <span style="font-size: large; color: rgba(139, 0, 0, 1)">Select reason to Hold the Records|</span>
                                <div class="form-group">
                                    <asp:dropdownlist id="ddlReason" runat="server" cssclass="form-control" onchange="ddlChanged(this)">
                                        <asp:listitem value="0">--Select Reason--
                                        <asp:listitem value="1">Beneficiary Expired
                                        <asp:listitem value="2">Member Already Beneficiary                                        
                                        <asp:listitem value="3">Others
                                    
                                </div>
                            </div>

                            <div class="col-md-4" id="div_otherreason">
                                <span style="font-size: large; color: rgba(139, 0, 0, 1)">Enter Other reason Here |</span>
                                <div class="form-group">
                                    <asp:textbox id="txt_reason" runat="server" cssclass="form-control" autocomplete="off">
                                </div>
                            </div>

                            <div class="col-md-4">
                                <asp:button id="btn_Hold" runat="server" text="Click Here for Hold" cssclass="btn btn-danger" onclientclick="ShowLoading();" onclick="btn_Hold_Click" style="margin-top: 25px">
                            </div>


What I have tried:

I tried every possiblity, but not getting the solution, i need to div_otherreason will be visible after postback
Posted
Updated 29-Oct-20 3:10am
v2
Comments
[no name] 29-Oct-20 9:40am    
You also set the value to ''; effectively creating a zero-length field. Just try "disabling" it for starters.
Richard Deeming 29-Oct-20 11:36am    
In one branch, you're setting the display property; in the other, you're setting the display AND visibility properties. You need to pick one and use it consistently.

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