Ajax - input submit vs onchange = this.submit.form()http://forums.asp.net/t/1770571.aspx/1?Ajax+input+submit+vs+onchange+this+submit+form+Tue, 21 Feb 2012 17:25:01 -050017705714836732http://forums.asp.net/p/1770571/4836732.aspx/1?Ajax+input+submit+vs+onchange+this+submit+form+Ajax - input submit vs onchange = this.submit.form() <p>Im working on a series of dropdown lists that populate other dropdown lists based on the selected value. Originally I had it so that the form would auto submit if the value was changed but the entire page was getting refreshed instead of just refreshing the drop down. After exhausting all other solutions I ended up removing the onchange = this.submit.form() and just added an input submit button and I got the desired results. Here are the two solutions:</p> <p>&nbsp;</p> <pre class="prettyprint">Solution #1 - Refreshes entire page @using (Ajax.BeginForm(&quot;BySite&quot;, &quot;Building&quot;, new AjaxOptions { UpdateTargetId = &quot;buildingDropDown&quot;, InsertionMode = InsertionMode.Replace, HttpMethod = &quot;GET&quot; })) { @Html.DropDownList(&quot;SiteID&quot;, null, new { onchange = &quot;this.form.submit()&quot; }) } &lt;div id=&quot;buildingDropDown&quot;&gt;&lt;/div&gt;</pre> <pre class="prettyprint">Solution #2 - Adds dropdown to current page (expected) <br /><br />@using (Ajax.BeginForm("BySite", "Building", new AjaxOptions { UpdateTargetId = "buildingDropDown", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" })) { @Html.DropDownList("SiteID") &lt;input type="submit" value="Go" name="submit" /&gt; } &lt;div id="buildingDropDown"&gt;&lt;/div&gt;</pre> <p>&nbsp;</p> <p>Is there a different way to submit the form onchange that doesn't refresh the entire page?</p> 2012-02-16T21:38:56-05:004840099http://forums.asp.net/p/1770571/4840099.aspx/1?Re+Ajax+input+submit+vs+onchange+this+submit+form+Re: Ajax - input submit vs onchange = this.submit.form() <p>Hello</p> <p>You may try onsubmit handler in place of submit call</p> <p>onchange = &quot;this.form.onsubmit()&quot;</p> <p>&nbsp;</p> 2012-02-20T02:42:16-05:004843606http://forums.asp.net/p/1770571/4843606.aspx/1?Re+Ajax+input+submit+vs+onchange+this+submit+form+Re: Ajax - input submit vs onchange = this.submit.form() <p>I was able to get it working as desired with the following code:</p> <pre class="prettyprint">&lt;script type=&quot;text/jscript&quot;&gt; $(document).ready(function () { $('#SiteID').change(function () { $('#SiteID').closest(&quot;form&quot;).submit(); }); }); &lt;/script&gt;</pre> <p></p> 2012-02-21T17:25:01-05:00