# Observe\_field using :on =\> select not working

**URL:** <https://www.ruby-forum.com/t/observe-field-using-on-select-not-working/109953>\
**Category:** Rails\
**Created:** [July 20, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/observe-field-using-on-select-not-working/109953 "2007-07-20T17:07:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [July 20, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/observe-field-using-on-select-not-working/109953/1 "2007-07-20T17:07:31Z")

</div>

Is there a known bug with observe\_field using the :on parameter?

I want to observe a select list, and only update a child select list  
after someone has made a selection, so I want to use the onSelect  
event. However no matter what I set as the value of :on it still  
behaves as if it is set to change (the default).

I came across this [http://joshhuckabee.com/taxonomy/term/5](http://joshhuckabee.com/taxonomy/term/5) which  
implies there is a bug - I even change my prototype.js to match his  
changes, but it still is not behaving as I would have expected.

I have used onSelect before in select lists, and it definitely only  
fires when you actually make the selection, so I am very confused!

---

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [July 20, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/observe-field-using-on-select-not-working/109953/2 "2007-07-20T19:13:48Z")

</div>

I was frustrated with this as well; there isn’t good documentation  
online. Or, if there is, I couldn’t easily find it. I got this  
information through bugging a bunch of people in IRC.

## It might be better to do it this way:

## \<%= collection\_select(“rates\_calc”, “origin\_id”, @locations, :id, :name, {}, {:onchange =\> remote\_function(:url =\> {:action =\> “show\_origin\_sublocations”}, :with =\> encodeURI\_selection(“rates\_calc”, “origin\_id”, “value”) ) } ) %\>

## where is a helper:

def encodeURI\_selection(object, method, value)  
return “‘#{method}=’ + encodeURIComponent(” +  
get\_element\_by\_method(object, method, value) + “)”  
end

## def get\_element\_by\_method(object, method, value) return “document.getElementById(‘#{object}\_#{method}’).#{value}” end

basically, show\_origin\_sublocations will call an RJS which will have  
your JS code to do whatever you want.

On 7/20/07, stephen O’D [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> changes, but it still is not behaving as I would have expected.
> 
> I have used onSelect before in select lists, and it definitely only  
> fires when you actually make the selection, so I am very confused!
> 
> >

–  
Ramon T.

---

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [July 20, 2007, 9:40pm UTC](https://www.ruby-forum.com/t/observe-field-using-on-select-not-working/109953/3 "2007-07-20T21:40:08Z")

</div>

On Jul 20, 6:13 pm, “Ramon Miguel M. Tayag” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> * * *
> 
> basically, show\_origin\_sublocations will call an RJS which will have  
> your JS code to do whatever you want.

Interesting - I will give that a go tomorrow and hopefully it works  
out better. So frustrating with the observe method, as its so simple!

---

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [July 21, 2007, 3:11pm UTC](https://www.ruby-forum.com/t/observe-field-using-on-select-not-working/109953/4 "2007-07-21T15:11:27Z")

</div>

On Jul 20, 6:13 pm, “Ramon Miguel M. Tayag” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> * * *
> 
> basically, show\_origin\_sublocations will call an RJS which will have  
> your JS code to do whatever you want.

I got the observe\_file method working - upon re-reading the docs, it  
seemed that not setting the frequency parameter was the way to achieve  
what I wanted, and that onchange was infact the correct event to check  
for when using a select list.

Cheers,

Stephen.
