user1175969
user1175969

Reputation: 570

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:

$('#hidden_id').val("ABC");

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")?

Upvotes: 2

Views: 1499

Answers (1)

Saad
Saad

Reputation: 1904

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.

Upvotes: 3

Related Questions