Reputation: 265
Here's my code - I've checked my development log and it shows that the form is not being submitted.
I know I can do it by adding a submit tag, but I don't want to do this. I want it to submit automatically when I check the box.
What am I missing?
<h>
<%= form_tag do %>
<%= check_box_tag(:zagat_status) %>
<%= label_tag(:zagat_status, "Zagat status") %>
<% end %>
</h>
Javascript code
<script type="javascript">
$(function() {
$("h").click(function() {
$(this).find('input:checkbox').prop("checked", true);
});
});
</script>
Upvotes: 0
Views: 47
Reputation: 2156
You can use the Rails built-in AJAX functionality (i.e. add remote: true
to the form_tag
).
<%= form_tag('/YOUR_URL_GOES_HERE', remote: true) do %>
<%= check_box_tag(:zagat_status, true) %>
<%= label_tag(:zagat_status, "Zagat status") %>
<% end %>
<script type="text/javascript">
$(function(){
$("form").on('change', "input:checkbox", function(){
$("form").submit()
})
})
</script>
Upvotes: 1