Topic: Form submission via javascript

I can submit form in javascript with

$("#my_form_id").trigger("submit.rails");

Is there a way in javascript to pass some values with this trigger? I'd need something like "back_button" in

<%= f.submit "Back", class: "btn", :name => "back_button" %>

to handle it in submit action in controller.


Thank you for help

Re: Form submission via javascript

Indeed neither .trigger() nor .submit() send the button's name attribute along.  What about adding a hidden form field or changing the form's action attribute?  (http://stackoverflow.com/questions/2530 … t-not-ajax)

You could also hijack the submission itself:  http://stackoverflow.com/questions/1086 … submission

Re: Form submission via javascript

Thank you for hints. A day of google 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");