# Html options :onkeypress

**URL:** <https://www.ruby-forum.com/t/html-options-onkeypress/84263>\
**Category:** Rails\
**Created:** [February 2, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/html-options-onkeypress/84263 "2007-02-02T20:17:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 2, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/html-options-onkeypress/84263/1 "2007-02-02T20:17:16Z")

</div>

Good evening,

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

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…

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 2, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/html-options-onkeypress/84263/2 "2007-02-02T20:27:14Z")

</div>

Well, from what you’ve posted, it looks like you want to use  
observe\_field.  
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.

Jason

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [February 2, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/html-options-onkeypress/84263/3 "2007-02-02T23:40:35Z")

</div>

well, one thought would be to set a flag on the first keypress.

something like

\<%= text\_area …, :onkeypress =\> “mykeypress()” -%\>
