user1175969 user1175969 - 4 months ago 15
Javascript Question

Use jQuery to set value of hidden field in a form and submit the value

I am using jQuery to assign a value to a hidden field:


In my View, I have:

<%= hidden_field_tag(:id => "hidden_id", :val => "") %>

How do I pass the value "ABC" from the form to to my Controller (through the param ":val")?


You should be defining your hidden_field_tag like this

  <%= hidden_field_tag 'hidden', '', id: 'hidden_id' %>

  equivalent to
  <input type="hidden" name="hidden" id="hidden_id" value="">

take a look at the documentation for help.