# Select\_tag - observe field

**URL:** <https://www.ruby-forum.com/t/select-tag-observe-field/133037>\
**Category:** Rails\
**Created:** [March 26, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/select-tag-observe-field/133037 "2008-03-26T23:03:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [March 26, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/select-tag-observe-field/133037/1 "2008-03-26T23:03:35Z")

</div>

I’m trying to do an ajax call when the select (drop down) gets changed.  
What’s the best way to do this?

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [March 27, 2008, 4:25am UTC](https://www.ruby-forum.com/t/select-tag-observe-field/133037/2 "2008-03-27T04:25:57Z")

</div>

On Thu, Mar 27, 2008 at 9:03 AM, Jimmy P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to do an ajax call when the select (drop down) gets changed.  
> What’s the best way to do this?

I wrote up something similar here:

[http://lindsaar.net/2008/2/25/javascript-field-monitor](http://lindsaar.net/2008/2/25/javascript-field-monitor)

This is a javascript file that monitors every input and select on a  
form and highlights it if it changes.

You can replace the highlight code with an AJAX call if you want.

Regards

Mikel

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [April 5, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/select-tag-observe-field/133037/3 "2008-04-05T17:06:48Z")

</div>

Here’s how to put an observer on a select box:

VIEW:  
\<%= select\_tag :card\_type, %{Please Select…}  
+  
options\_for\_select(supported\_card\_types) %\>

\<%= observe\_field :card\_type,  
:frequency =\> 0.5,  
:url =\> {:action =\> :display\_card\_fields, :only\_path  
=\> :false},  
:with =\> “‘card\_type=’+encodeURIComponent(value)” %\>

This calls RJS file “display\_card\_fields.js.rjs” when the select box  
changes, sending the value card\_type in the params hash.

Hope this helps you 🙂
