Reputation: 23
I found partial answer in Rails 3: How to trigger a form submission via javascript?
I can trigger form submit with
$("#form_id").trigger("submit.rails");
But I can't find a way to pass some value to submit like I would send "back_button" to controller with
<%= f.submit "Back", class: "btn", :name => "back_button" %>
Is there a way to do this in javascript?
Upvotes: 0
Views: 69
Reputation: 23
A day of googling and testing I found a working sollution. For those who may encounter the same problem here is the code:
var data = $("#my_form_id").serializeArray();
data.push({"name":"your_key_to_add_to_submit","value":"your_value"});
$.post("url_for_submit", $.param(data), null, "script");
Upvotes: 1