I have the following rails form (which works) but I want to remove the submit_tag and have the form submit as soon as a radio button selection is made. How do I do that?
<I am doing something similar so this question really helps.
Further to Ash's answer, I found that the above onclick function does not work, I have changed a bit and the form below work just fine to me:
<% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do %>
<% for i in 1..10 do %>
<%= radio_button_tag :rating, i, false, :onclick => "this.form.submit();" %> <%=h i %>
<% end %>
<% end %>
Hope it would help somebody.
You'll want to add an onClick event to your radio button that calls this.formName.submit() where formName is your form ID. This will trigger the submit event when you click the radio button.
So I have found the precise solution (thanks for the input guys, it helped me redefine my Google searches). Everyone was on the right track, but none were spot on.
All that was needed was to add 'false, :onclick => "this.parentNode.submit();"' to the radio_button_tag form helper. The false is selected or not, and the rest is obvious.
The correct solution now looks like:
<% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do %>
<% for i in 1..10 do %>
<%= radio_button_tag :rating, i, false, :onclick => "this.parentNode.submit();" %> <%=h i %>
<% end %>
<% end %>