I have a form with only a checkbox. When the user clicks this checkbox I
want to submit the form through AJAX. It’s like a TODO-list where you
can
mark the item as done by ticking a box.
So, how can I do this? I’m using Rails 3.1.
I guess there is no native function to achieve this. So far I have this:
My form in the view:
<%= form_for [@list, item], :remote => true do |f| %>
<%= f.check_box :status %>
<% end %>
Then in my javascript file I guess I need to do something like (coffee):
$(‘input#item_status’).live ‘click’, (e) ->
form = $(this).parent('form')
/* SUBMIT FORM HERE! */
Hehe great! I actually tried it in an onClick="" but that didn’t submit
the
form through AJAX so I didn’t think it would work when doing it directly
in
jQuery either It does work indeed.
And I now I don’t need the param (e). It’s a habit to pass in case I
need
it. Otherwise I remove it
Thanks for the quick help!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.