I try to create an "onKeypress" event handler for a form but nothing works!
I have already studied the reference books on Ajax, but that didn't help. Can someone explain me how todo this?
These are the code-snippets:
1) application.js
var GridControlTracker = {} GridControlTracker = { gridEventHandler: function(element, value) { alert('Key Pressed / element: '+ element.id); } }
2) show.rhtml
<%= observe_form "grid-form", :frequency => 0, :function => "GridControlTracker.gridEventHandler(element,value)", :on => "keypress" %>
this generates this javascript in the page:
<script type="text/javascript"> //<![CDATA[ new Form.Observer('grid-form', 0, function(element, value) {GridControlTracker.gridEventHandler(element,value)}, 'keypress') //]]> </script>
These are the questions that I have: 1. Only the <backspace> and new input-characters are triggered. But I would like to trigger the navigation buttons (left, right, up, down, home ...) 2. I can't find the way to work with the event object. It must be instantiated, but how can I work with it? 3. I don't see the usage of observe_form with the function option (instead of URL) in code examples. Is this the correct way? I want to filter the events that I want to handle and than go to the server for the selected events. Is this the only way to do this?
thanks and sjamayee!