# How to make a drop-down automatically submit an AJAX form

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-drop-down-automatically-submit-an-ajax-form/50783>\
**Category:** Rails\
**Created:** [December 21, 2005, 3:48am UTC](https://www.ruby-forum.com/t/how-to-make-a-drop-down-automatically-submit-an-ajax-form/50783 "2005-12-21T03:48:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 21, 2005, 3:48am UTC](https://www.ruby-forum.com/t/how-to-make-a-drop-down-automatically-submit-an-ajax-form/50783/1 "2005-12-21T03:48:15Z")

</div>

Hi,  
I know that to make a dropdown box automatically submit when you change  
the value, you do this:  
\<select … onchange=“this.form.submit();”\>  
BUT i’ve got an ajax form, and if i do the above trick, it simply  
reloads the ajax partial into the whole screen, rather than into the div  
where it is meant to go.  
I’ve already got it all working so that if you click on the submit  
button, all is fine, but i’d like to know how to make it automatic.

My RHTML code looks a bit like this:

–  
\<%= form\_remote\_tag :update =\> “div\_id\_dataentry\_bottom\_ajax”, :url =\> {  
:action =\> “dataentry\_bottom\_edit” } %\>

\<%= options\_from\_collection\_for\_select @departments, “id”,  
“department\_name” %\>

\<%= submit\_tag “Open for Data Entry” %\>

\<%= end\_form\_tag %\>

--

Cheers, thanks all

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 21, 2005, 6:00am UTC](https://www.ruby-forum.com/t/how-to-make-a-drop-down-automatically-submit-an-ajax-form/50783/2 "2005-12-21T06:00:41Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 21, 2005, 7:56am UTC](https://www.ruby-forum.com/t/how-to-make-a-drop-down-automatically-submit-an-ajax-form/50783/3 "2005-12-21T07:56:33Z")

</div>

Use onchange=“this.form.onsubmit();” rather than submit straight.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 21, 2005, 11:02pm UTC](https://www.ruby-forum.com/t/how-to-make-a-drop-down-automatically-submit-an-ajax-form/50783/4 "2005-12-21T23:02:09Z")

</div>

Raghuraman Suraj wrote:

> Use onchange=“this.form.onsubmit();” rather than submit straight.

Brilliant!
