# Keypress events with no AJAX needed

**URL:** <https://www.ruby-forum.com/t/keypress-events-with-no-ajax-needed/54707>\
**Category:** Rails\
**Created:** [March 13, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/keypress-events-with-no-ajax-needed/54707 "2006-03-13T15:54:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 13, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/keypress-events-with-no-ajax-needed/54707/1 "2006-03-13T15:54:06Z")

</div>

Is anyone else finding it frustrating to do in Ruby client-side things  
that would be simple in Javascript?  
It seems like all of the “helpers” involve server (controller)  
communication.

For example, having a text field that just echos below what the user  
types.  
Is this the only way to do it?

 \<%= text\_field\_tag 'user\_text'%\> \<%= javascript\_tag("Event.observe('user\_text', 'keypress', function(event) { Element.update('stylized\_word', $F(Event.element(event)));})")%\>

Thank you!  
Chris

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 13, 2006, 4:23pm UTC](https://www.ruby-forum.com/t/keypress-events-with-no-ajax-needed/54707/2 "2006-03-13T16:23:02Z")

</div>

Chris, this is just the example. You might want to use that for chat for  
example, where text that user types appears not only on his computer,  
but for others.

Clearly, if you are doing it for one user there is no point in using  
server-side, but again this is just the example  
Chris H. wrote:

> Is anyone else finding it frustrating to do in Ruby client-side things  
> that would be simple in Javascript?  
> It seems like all of the “helpers” involve server (controller)  
> communication.
> 
> For example, having a text field that just echos below what the user  
> types.  
> Is this the only way to do it?
> 
> \<%= text\_field\_tag 'user\_text'%\> \<%= javascript\_tag("Event.observe('user\_text', 'keypress', function(event) { Element.update('stylized\_word', $F(Event.element(event)));})")%\>
> 
> Thank you!  
> Chris

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 13, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/keypress-events-with-no-ajax-needed/54707/3 "2006-03-13T16:31:28Z")

</div>

Chris H. wrote:

> Is anyone else finding it frustrating to do in Ruby client-side things  
> that would be simple in Javascript?  
> It seems like all of the “helpers” involve server (controller)  
> communication.  
> The reason for that is extremely simple. Where there’s server  
> communication, you need a convenient way of keeping the client-side and  
> server-side code in sync. That’s what the helpers help with. If all  
> you’re doing is client-side manipulation, you almost certainly don’t  
> need the helpers. Just use Javascript.

> For example, having a text field that just echos below what the user  
> types.  
> Is this the only way to do it?  
> Personally, I wouldn’t bother with the \<%= javascript\_tag %\> call at  
> all…
