0

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?

1
  • Do you want to submit the for upon changing some value? Commented Apr 2, 2013 at 10:15

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

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.