# Form submit onchange of dropdown

**URL:** <https://www.ruby-forum.com/t/form-submit-onchange-of-dropdown/119910>\
**Category:** Rails\
**Created:** [November 12, 2007, 3:55am UTC](https://www.ruby-forum.com/t/form-submit-onchange-of-dropdown/119910 "2007-11-12T03:55:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artybala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de0a6/32.png) [@artybala](https://www.ruby-forum.com/u/artybala)\
**Post date:** [November 12, 2007, 3:55am UTC](https://www.ruby-forum.com/t/form-submit-onchange-of-dropdown/119910/1 "2007-11-12T03:55:30Z")

</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:** ![artybala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de0a6/32.png) [@artybala](https://www.ruby-forum.com/u/artybala)\
**Post date:** [November 12, 2007, 4:28am UTC](https://www.ruby-forum.com/t/form-submit-onchange-of-dropdown/119910/2 "2007-11-12T04:28:14Z")

</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)
