Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Server Controls - Show Hide Textbox based on Dropdown selection
    primarykey
    data
    text
    <p>What is the best way to show/hide a textbox or an entire div section based on a users selection from a dropdown? I don't believe its possible with server controls, so I would have to use regular client side HTML controls, correct? Thanks for any input. Would jQuery be the best option for this? Is there a way to hide the Div by default and then show it when the user selects the option from the drop down?</p> <pre><code>&lt;div id="divLimitPrice"&gt;Limit Price&lt;br /&gt; &lt;asp:TextBox ID="txtLimitPrice" runat="server" ValidationGroup="ValidationGroupOrder"&gt;&lt;/asp:TextBox&gt; &amp;nbsp;&lt;asp:RequiredFieldValidator ID="rfvLimitPrice" runat="server" ControlToValidate="txtLimitPrice" ErrorMessage="This is a required field."&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $(function () { $('[id*="ddPriceType"]').on('change', function () { var val = this.value, $divLimitPrice = $('[id*="divLimitPrice"]'); if (val === 1 || val === 2) { // Hide div group $divLimitPrice.hide(); } else { // Show div group $divLimitPrice.show(); } }); }); &lt;/script&gt; Price Type&lt;br /&gt; &lt;asp:DropDownList ID="ddPriceType" runat="server" ValidationGroup="ValidationGroupOrder"&gt; &lt;asp:ListItem Value="" Text ="Select a Price Type" /&gt; &lt;asp:ListItem Value="2" text="Type 2" /&gt; &lt;asp:ListItem Value="3" text="Type 3" /&gt; &lt;asp:ListItem Value="4" text="Type 4" /&gt; &lt;/asp:DropDownList&gt; &amp;nbsp;&lt;asp:RequiredFieldValidator ID="rfvPriceType" runat="server" ControlToValidate="ddPriceType" ErrorMessage="This is a required field."&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;div id="divLimitPrice"&gt;Limit Price&lt;br /&gt; &lt;asp:TextBox ID="txtLimitPrice" runat="server" ValidationGroup="ValidationGroupOrder"&gt;&lt;/asp:TextBox&gt; &amp;nbsp;&lt;asp:RequiredFieldValidator ID="rfvLimitPrice" runat="server" ControlToValidate="txtLimitPrice" ErrorMessage="This is a required field."&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;/div&gt;` </code></pre> <p>Hmm.. I tried adapting the code and I am missing something! Any thoughts? Thank you for your time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload