# Select list and observe\_field problem

**URL:** <https://www.ruby-forum.com/t/select-list-and-observe-field-problem/115127>\
**Category:** Rails\
**Created:** [September 20, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/select-list-and-observe-field-problem/115127 "2007-09-20T20:48:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 20, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/select-list-and-observe-field-problem/115127/1 "2007-09-20T20:48:23Z")

</div>

Hey all,

I have attached an observe\_field to a select box in one of my views in  
order to trigger a function when the user selects a new item.  
The problem is that I can not seem to be able to convince it by any  
means to call the function _only_ when a new item is really chosen (and  
not just hovering over it).

I have tried to hook on every kind of event with the :on =\> ‘blabla’  
option, but no matter what I have used, the function is called also when  
I am hovering over an item but not actually selecting it. Is it possible  
to achieve this at all? (I am sure it is but I am a bit frustrated after  
all this googling around ☹

Any ideas? Thanks a million.

Cheers,  
Peter

\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)  
[http://scrubyt.org](http://scrubyt.org)

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 20, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/select-list-and-observe-field-problem/115127/2 "2007-09-20T21:13:26Z")

</div>

yes, it’s the :on option. From the docs:

:on  
Specifies which event handler to observe. By default, it’s set to  
“changed” for text fields and areas and “click” for radio buttons and  
checkboxes. With this, you can specify it instead to be “blur” or  
“focus” or any other event.

so it would be observe\_field :field\_id, :on =\> ‘change’

Peter S. wrote:

> I am hovering over an item but not actually selecting it. Is it possible  
> [http://scrubyt.org](http://scrubyt.org)
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 21, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/select-list-and-observe-field-problem/115127/3 "2007-09-21T15:45:55Z")

</div>

I am using it in my app on a few occasions for pagination, etc and it is  
working well. Have you validated your markup?

Peter S. wrote:

> > so it would be observe\_field :field\_id, :on =\> ‘change’  
> > [http://scrubyt.org](http://scrubyt.org)
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 21, 2007, 9:01am UTC](https://www.ruby-forum.com/t/select-list-and-observe-field-problem/115127/4 "2007-09-21T09:01:51Z")

</div>

William P. wrote:

> yes, it’s the :on option. From the docs:
> 
> :on  
> Specifies which event handler to observe. By default, it’s set to  
> “changed” for text fields and areas and “click” for radio buttons and  
> checkboxes. With this, you can specify it instead to be “blur” or  
> “focus” or any other event.
> 
> so it would be observe\_field :field\_id, :on =\> ‘change’

of course, I have tried that, and also other events, but nothing worked.  
It still triggers on hovering, too (also with :on =\> ‘change’ or :on =\>  
‘click’)…

Cheers,  
Peter  
\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)  
[http://scrubyt.org](http://scrubyt.org)
