Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails remote form submit through javascript

I'm trying to create a very small simple form that edits a single checkbox, and submits automatically with AJAX when the checkbox is modified. Here's the code, which other SO questions imply should work:

    <%= form_for(workitem, :remote => true) do |f| %>
      <%= f.check_box :is_complete, :onchange => 'this.form.submit()' %>
    <% end %>

The problem is that this results in a full page HTML submit, rather than an AJAX submit. How do I trigger an AJAX submit?

like image 955
Leopd Avatar asked Jan 18 '26 21:01

Leopd


1 Answers

This seems to work:

$(this.form).submit();

Good 'ol jquery to the rescue.

like image 165
Leopd Avatar answered Jan 21 '26 11:01

Leopd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!