# Catching "keypress" event with observe\_field

**URL:** <https://www.ruby-forum.com/t/catching-keypress-event-with-observe-field/102219>\
**Category:** Rails\
**Created:** [August 13, 2006, 2:57am UTC](https://www.ruby-forum.com/t/catching-keypress-event-with-observe-field/102219 "2006-08-13T02:57:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@GaSSSSl](https://www.ruby-forum.com/u/GaSSSSl)\
**Post date:** [August 13, 2006, 2:57am UTC](https://www.ruby-forum.com/t/catching-keypress-event-with-observe-field/102219/1 "2006-08-13T02:57:16Z")

</div>

I’m desperately trying to update a div when a key is pressed in a text  
field.

Eg. :

\<%= observe\_field :field, :url =\> {:action =\> :myAction}, :update =\> :area, :with =\> "text\_param", :on =\> 'keypress' %\>

This does not seem to work, and I can’t understand why. Does someone  
have any clue on what I am doing wrong ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![GaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@GaSSSSl](https://www.ruby-forum.com/u/GaSSSSl)\
**Post date:** [August 13, 2006, 3:10am UTC](https://www.ruby-forum.com/t/catching-keypress-event-with-observe-field/102219/2 "2006-08-13T03:10:46Z")

</div>

I don’t use AJAX, but I’ll see if I can help.

Just some thoughts:

1. Right click on the loaded page and view source to make sure  
javascript is in the headers. Maybe observe\_field isn’t being loaded.
2. Instead of using keypress, does it work with frequency? I know that  
is not what you want, but it might give you some ideas.
3. Try text\_field\_tag as well for the input.

---

<div class="post-metadata">

**Author:** ![GaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@GaSSSSl](https://www.ruby-forum.com/u/GaSSSSl)\
**Post date:** [August 13, 2006, 3:17am UTC](https://www.ruby-forum.com/t/catching-keypress-event-with-observe-field/102219/3 "2006-08-13T03:17:56Z")

</div>

Thanks for you reply !

> 1. Right click on the loaded page and view source to make sure  
> javascript is in the headers. Maybe observe\_field isn’t being loaded.

Yep, it’s loaded.

> 1. Instead of using keypress, does it work with frequency? I know that  
> is not what you want, but it might give you some ideas.

Already done that, and yes, it works very well.

> 1. Try text\_field\_tag as well for the input.

Just tried, but it doesn’t work either. I really don’t know what to try  
next…

Thanks anyway
