Capturing arbitrary events in client-side DOM

I was wondering if there was any support a’la observe_field for
capturing
arbitrary events and triggering an AJAX postback.

For example, let’s consider this chunk of HTML:

Button 1
Button 2
Button 3

function handle_any_click_on_child_element() {
element = get_element_that_was_clicked_on();
ajax_post_back(element.id http://element.id);
}

Thanks,
-John

On Friday 18 November 2005 10:58 pm, John L. wrote:

I was wondering if there was any support a’la observe_field for capturing
arbitrary events and triggering an AJAX postback.

Add some JavaScript triggers?:

(A List Apart’s CMS is actually powered by Rails)

Rails leans towards beautiful rhtml, but the observe_field helper drops
javascript bang in the middle of your html. MVC is one thing, but for
separate presentation, behavioural, and structural layers on the browser
side
of things, try the JavaScript triggers article and the excellent
accessible
pop-up links article:

To apply this to rails, the prototype library gives you $(‘element_id’)
to
supplant the getElementById function used in the articles, and you can
either
place your triggers in an external JS file and link it in with a
javascript_include_tag in your layout, or use

in your layout and

<% content_for(“page_scripts”) do -%>
/* insert JS here */
<% end -%>

in your templates to customise events by controller/action.

Maybe examine the code generated by the observe_field helper and apply
some A
List Apart goodness to it. Haven’t tried it personally, but am meaning
to do
so in the near future… Any comments Mr Dan Benjamin?
http://www.alistapart.com/authors/b/danbenjamin/

Mark B.
Easy Schedule Management
http://easy-online-schedule.com