Submit a remote form with a checkbox

I’m having a difficult time figuring out how to submit a remote (AJAX)
form using the onclick of a checkbox. A normal submit button works fine,
but the following statement submits the form normally, seemingly
bypassing AJAX altogether:

<%= check_box “report”, “item”, :onclick => “this.form.submit()” %>

I can’t simply use a remote_function because I need the form to actually
submit so that the other fields on the form can be saved. How can I go
about this?

Problem solved. For those interested in the solution, it turns out that
the problem is a fundamental javascript issue, where
onclick=“this.form.submit()” completely ignores a form’s “onsubmit”
event. The solution is to put the entire ajax command in the onclick of
your checkbox.

So it turns out remote_function was the way to go afterall. The trick is
to give the form a DOM element id and then add the :submit parameter to
the remote_function, pointing to the form’s id. Here’s an example of how
it works:

<%= form_remote_tag :update => “some_div”, :url => { :action => “save”
}, :html => { :id => “dom_id” } %>

<%= check_box “report”, “word”, :onclick => remote_function(:update =>
“some_div”, :url => { :action => “save” }, :submit => “dom_id”) %>