# Form submit onchange of dropdown

**URL:** <https://discuss.rubyonrails.org/t/form-submit-onchange-of-dropdown/20305>\
**Category:** rubyonrails-talk\
**Created:** [November 12, 2007, 2:54am UTC](https://discuss.rubyonrails.org/t/form-submit-onchange-of-dropdown/20305 "2007-11-12T02:54:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artybala](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@artybala](https://discuss.rubyonrails.org/u/artybala)\
**Post date:** [November 12, 2007, 2:54am UTC](https://discuss.rubyonrails.org/t/form-submit-onchange-of-dropdown/20305/1 "2007-11-12T02:54:55Z")

</div>

Hi.,

Need help in learning how to submit a Form when a drop down value changes. I am using form\_remote\_tag . I want detail rows to be retrieved below automatically based on the value selected. ( Ex: Automatically list the students when you select the school name from the dropdown) . I am able to do it when I explicitly submit it using the submit\_tag , but I want the form to be submitted as soon as the value changes with having to use the submit button. I am a newbie to Rails and would truly appreciate the help.

Thanks. Artybala

---

<div class="post-metadata">

**Author:** ![Matt\_Swasey](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Matt\_Swasey](https://discuss.rubyonrails.org/u/Matt_Swasey)\
**Post date:** [November 12, 2007, 3:20am UTC](https://discuss.rubyonrails.org/t/form-submit-onchange-of-dropdown/20305/2 "2007-11-12T03:20:35Z")

</div>

The best way to do this is to use the observe\_field method.  
Basically, you want to do this: (in the view)

Create a drop down:

\<%= collection\_select :user, :favorite\_color, @colors, "id", "name %\>

then somewhere below that, create an observe\_field

\<%= observe\_field "user\_favorite\_color", :action =\> "do\_something" %\>

For more information, lookup collection\_select and observe\_field in  
your favorite rails api format. I am partial to railsbrain:

collection\_select: [http://railsbrain.com/api/rails-1.2.4/doc/index.html?a=M001655&name=collection\_select](http://railsbrain.com/api/rails-1.2.4/doc/index.html?a=M001655&name=collection_select)

observe\_field: [http://railsbrain.com/api/rails-1.2.4/doc/index.html?a=M001683&name=observe\_field](http://railsbrain.com/api/rails-1.2.4/doc/index.html?a=M001683&name=observe_field)
