user1175969 user1175969 - 1 year ago 71
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")?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download