ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Dynamically add TextBoxes based on DropDownList value in jQuery<p>Refer below article.</p> <h1 class="header"><a title="Dynamically add and remove TextBoxes using jQuery'a" href="https://www.aspsnippets.com/Articles/Dynamically-add-and-remove-TextBoxes-using-jQuery.aspx">Dynamically add and remove TextBoxes using jQuery</a></h1>https://www.aspforums.net:443/Threads/115689/Dynamically-add-TextBoxes-based-on-DropDownList-value-in-jQuery/https://www.aspforums.net:443/Threads/115689/Dynamically-add-TextBoxes-based-on-DropDownList-value-in-jQuery/Mon, 08 Oct 2018 05:10:35 GMTDynamically add TextBoxes based on DropDownList value in jQuery<p>Hi <a class="username" rel="himani895"> himani895</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { var values = eval(&#39;&lt;%=Values%&gt;&#39;); if (values != null) { var html = &#34;&#34;; $(values).each(function () { var div = $(&#34;&lt;div /&gt;&#34;); div.html(&#39;&lt;input name = &#34;DynamicTextBox&#34; type=&#34;text&#34; value = &#34;&#39; + this + &#39;&#34; /&gt;&#39;); $(&#34;#divDynamic&#34;).append(div); }); } $(&#39;[id*=ddlNumber]&#39;).change(function () { $(&#34;#divDynamic&#34;).empty(); for (var i = 0; i &lt; $(this).val(); i++) { var textbox = $(document.createElement(&#39;div&#39;)).attr(&#34;id&#34;, &#39;divTxt&#39; + i); textbox.after().html(&#39;&lt;input name = &#34;DynamicTextBox&#34; type=&#34;text&#34; /&gt;&#39;); textbox.appendTo(&#34;#divDynamic&#34;); } }); }); &lt;/script&gt; &lt;div&gt; &lt;asp:DropDownList ID=&#34;ddlNumber&#34; runat=&#34;server&#34;&gt; &lt;asp:ListItem Text=&#34;1&#34; Value=&#34;1&#34;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&#34;2&#34; Value=&#34;2&#34;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&#34;3&#34; Value=&#34;3&#34;&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text=&#34;4&#34; Value=&#34;4&#34;&gt;&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;br /&gt; &lt;div id=&#34;divDynamic&#34;&gt; &lt;/div&gt; &lt;br /&gt; &lt;asp:Button ID=&#34;btnSave&#34; runat=&#34;server&#34; Text=&#34;Save&#34; OnClick=&#34;Save&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Web.Script.Serialization; using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Web.Script.Serialization Imports System.Data.SqlClient</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected string Values; protected void Save(object sender, EventArgs e) { string[] textboxValues = Request.Form.GetValues(&#34;DynamicTextBox&#34;); JavaScriptSerializer serializer = new JavaScriptSerializer(); this.Values = serializer.Serialize(textboxValues); foreach (string textboxValue in textboxValues) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;conSting&#34;].ConnectionString)) { using (SqlCommand cmd = new SqlCommand(&#34;INSERT INTO Customers (@CustomerId) VALUES(@CustomerId)&#34;, con)) { con.Open(); cmd.Parameters.AddWithValue(&#34;@CustomerId&#34;, textboxValue); cmd.ExecuteNonQuery(); con.Close(); } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Values As String Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs) Dim textboxValues As String() = Request.Form.GetValues(&#34;DynamicTextBox&#34;) Dim serializer As JavaScriptSerializer = New JavaScriptSerializer() Me.Values = serializer.Serialize(textboxValues) For Each textboxValue As String In textboxValues Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;conSting&#34;).ConnectionString) Using cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO Customers (@CustomerId) VALUES(@CustomerId)&#34;, con) con.Open() cmd.Parameters.AddWithValue(&#34;@CustomerId&#34;, textboxValue) cmd.ExecuteNonQuery() con.Close() End Using End Using Next End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://imgur.com/tdzVTWC.gif" alt="" width="248" height="235" /></span></strong></p>https://www.aspforums.net:443/Threads/115689/Dynamically-add-TextBoxes-based-on-DropDownList-value-in-jQuery/https://www.aspforums.net:443/Threads/115689/Dynamically-add-TextBoxes-based-on-DropDownList-value-in-jQuery/Tue, 09 Oct 2018 02:02:38 GMT