2

I have a form. I added a JQuery onchange submit to the number_field tag. The same i want to do for the check_box_tag. I want that the form get submitted if you click on one checkbox. i tried many options but i don't get it. Hope you can help me.

<%= form_tag("/rooms/list", method: "get", :name => "list", :remote => true) do %>
    <%= label_tag(:size, "gewünschte Raumgröße:") %>
    <%= number_field(:room, :size, in: 0.0..999999999, step: 1.0, :value => @size, :onchange => ("javascript: document.list.submit();")) %>
    <br>
    Equipment
    <br>
    <% @categories.each do |category| %>
        <%= check_box_tag(category, {:remote => true, :onclick => ("javascript: document.list.submit();")}) %>
        <%= label_tag(category, category) %>
    <% end %>
<% end %>
1
  • 1
    Hi, give an ID to your form and then write like "$(#ID).submit();", May these will solve your problem, If not then will suggest you another way. Let me know. Commented Dec 2, 2014 at 6:54

2 Answers 2

1

I got it!

<%= check_box_tag(category,true, false, :onclick => "javascript: document.list.submit();") %>
Sign up to request clarification or add additional context in comments.

Comments

1

@killerameise below solution works in >rails 4.2

<%= check_box_tag(category, category, false, onclick: "javascript: $(this).submit();") %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.