# Onblur to work with select

**URL:** <https://www.ruby-forum.com/t/onblur-to-work-with-select/116701>\
**Category:** Rails\
**Created:** [October 8, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/onblur-to-work-with-select/116701 "2007-10-08T21:06:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 8, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/onblur-to-work-with-select/116701/1 "2007-10-08T21:06:01Z")

</div>

I need a method to be called upon an ‘onblur’ event when a select list  
is no longer the focus - ideally, I would like it to work when the  
‘Enter’ key is hit. But, I am just trying to get the onblur to work,  
here is what I got:

\<%= select( “airlinemembership”, “membership”, Airline.find( :all,  
:order =\>  
‘name’ ).collect { |a| [a.name.downcase.capitalize, a.id]},  
{:update =\> ‘exclude\_1’}, {:onblur =\> ‘set\_exclude\_airline\_1’} ) %\>

Any ideas on how I can get the method ‘set\_exclude\_airline\_1’ to fire?  
Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 10, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/onblur-to-work-with-select/116701/2 "2007-10-10T22:39:42Z")

</div>

Hi,

I have tried to do this, but if you delve into the prototype  
javascript definitions I think the on blur is not actually implemented  
even though rails includes the option. I believe there is a way to  
detect the enter key in js, but I cant recall exactly how. What I  
ended up doing was to add a dummy field following the field I want to  
detect the blur. I then detect the on focus to do the call to remote,  
where I then do my update and use set focus to move to the next field.

Not ideal, but it achieves the desired result.

Tonypm
