Forum: Ruby on Rails Html options :onkeypress...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4d9d73356e22a5f76bd3f4020c416432?d=identicon&s=25 Matthew Williams (matt)
on 2007-02-02 20:17
Good evening,

I am having a bit of a problem and was wondering if anyone could help me

I have a form in my view, which contains a text_area. When the user
focuses on the text area and presses a key - i would like to execute an
action - only ONCE..

I can perform these events using :onkeypress => remote_function...

However, this obviously calls my funtion every time a key is pressed - i
would only like the function to be called once - is this a possibility??

any ideas of a work around??

Thanks for your time..
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-02-02 20:27
(Received via mailing list)
Well, from what you've posted, it looks like you want to use
So it would go something like this:

<%= text_field 'name', 'method', ... %>


<%= observe_field 'name[method]', :url => {:controller ... }, :update =>

Check out the API docs for full usage information, but this will send an
AJAX request when the user leaves the field.

A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-02 23:40
(Received via mailing list)
well, one thought would be to set a flag on the first keypress.

something like

<%= text_area ..., :onkeypress => "mykeypress()" -%>
<script type="text/javascript">
var key_flag = false;
function mykeypress() {
  if(key_flag == false) {
    key_flag = true;
    new AjaxRequest(...);
This topic is locked and can not be replied to.