views:

11

answers:

1

Hi!

I would like to extend my onclick parameter of button_to_remote with another javascript function call, but i couldn't find any answer for that. So i have sg like this:

button_to_remote('>', :url => {:action => "show_dtree", :id => tree_child.id, :dir1 => dir11, :dir2 => dir12}

what generates the following code:

<input onclick="new Ajax.Request('/d_trees/show_dtree/3?dir1=1&amp;dir2=2', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('2e8e2147c344bcee0edf40f8fe6072c12dc928d7')});" type="button" value="&gt;" />

And my aim would be to call a foo() function after the ajax request object instantiated:

<input onclick="new Ajax.Request('/d_trees/show_dtree/3?dir1=1&amp;dir2=2', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('2e8e2147c344bcee0edf40f8fe6072c12dc928d7')});foo();" type="button" value="&gt;" />

Is there any way to this beside to generate the whole button by myself?

Thanks for your help!

A: 

Sure, just add your function as a callback:

button_to_remote '>',
  :url => { :action => "show_dtree", :id => tree_child.id, :dir1 => dir11, :dir2 => dir12 },
  :complete => "foo()"

This will call foo when the Ajax request is complete. Instead of :complete you could use any of the other stages, e.g. :loading, :success, etc.

Jordan
thanks for your fast reply!
seriakillaz