# Observe\_field on select

**URL:** <https://www.ruby-forum.com/t/observe-field-on-select/171843>\
**Category:** Rails\
**Created:** [July 10, 2009, 3:35am UTC](https://www.ruby-forum.com/t/observe-field-on-select/171843 "2009-07-10T03:35:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 10, 2009, 3:35am UTC](https://www.ruby-forum.com/t/observe-field-on-select/171843/1 "2009-07-10T03:35:30Z")

</div>

I have an observe\_field on a select box. All works well,  
EXCEPT…this particular select box is a js masterpiece that allows  
it to be editable in selection index 0.

My problem thus is if someone selects the 0th item in the select box,  
types in a value, the observe\_field still picks it up in my controller  
as “” for params[‘channelnotes’].

Is there a way to amend the observe\_field to send back whatever the  
text is in the select box? (and not just when the user clicks on it to  
invoke the change, because then, of course, option 0 text is “”) I  
need to somehow just pass the text of the selected item in it whenever  
the text itself changes. Does anyone know observe\_field on select  
boxes well enough to know how to do this? -Janna B

\<SELECT name=“channelnotes” id=“channelnotes” style="width:350px;  
onKeyDown=“fnKeyDownHandler(this, event);” onKeyUp=“fnKeyUpHandler\_A  
(this, event); return false;” onKeyPress = “return fnKeyPressHandler\_A  
(this, event);” onChange=“fnChangeHandler\_A(this, event);”\>

 one two three

\<%= observe\_field “channelnotes”, :url =\> {:controller  
=\> :channels, :action =\> ‘notesboxchange’ }, :with =\> ‘channelnotes’ %\>

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 10, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/observe-field-on-select/171843/2 "2009-07-10T19:20:25Z")

</div>

On Thu, 2009-07-09 at 18:34 -0700, JannaB wrote:

> My problem thus is if someone selects the 0th item in the select box,  
> types in a value, the observe\_field still picks it up in my controller  
> as “” for params[‘channelnotes’].

observe\_field fires, by default, on the change event. There used to be  
an :on option you could use to modify its trigger. Don’t know if it’s  
still a valid option though. A little sandbox exercise would tell for  
sure. The bigger problem will probably be cross-browser support for  
whatever event you end up needing to trigger on for the edit case.  
Here’s a compatibility list:  
[http://www.quirksmode.org/dom/events/index.html](http://www.quirksmode.org/dom/events/index.html)

HTH,  
Bill
