How to use multiple buttons on the same form with AJAX?

Hi,

We are trying to use multiple submit buttons in the same form to tie to
different actions on the server side.

For example:

This works with non-AJAX type requests. However, now that we are trying
to
do the same with AJAX, it is not working. Whichever button we press, we
get
the value of the first button on the form being passed as a parameter to
the
server. It looks like to me the problem might be related to how Rails
generates its buttons with the same name (commit) but different values.
Is
this legal in AJAX? Does AJAX use DOM? Is there a work-around for this?

The parameters hash looks like…

“commit” => “edit”

even if we press the “cancel” or “test configuration” buttons.

I have Googled about but haven’t found any answers. Can anyone point me
in
the right direction or recommend a good book on AJAX?

Any help would be appreciated. Thanks,

cn

Chris,

If I recall, this is a known issue with XHR and you just can’t.

Ed

Edward F. wrote:

Chris,

If I recall, this is a known issue with XHR and you just can’t.

Ed

def onclick_button_to( label, *options)
button_to_function label, %Q{location.href=’#{url_for *options}’}
end

This is in my helper and what I use for my cancel buttons in my
multi-button forms. You pass the same parameters as you would for
link_to. In my view it looks like…

<%= form_tag :action => “save” %>
<%= onclick_button_to “cancel”, :action => “index” %>
<%= submit_tag ‘save’ %>
<%= end_form_tag %>

This is non-ajax usage but you would just need to modify the javascript
in the onclick_button_to method to get what you wanted…