Reputation: 21907
How do you pass a JQuery Element into a Rails hidden field?
Upvotes: 0
Views: 658
Reputation: 6382
I assume you want to do something like
<%= hidden_field_tag :hidden_field_id, $("input#hidden_field_value").val() %>
If that is the case, you wont be able to do it. As the ruby would be evaluated before the jquery would even run.
However you can get the val (or the id or what you want) by having
<script type="text/javascript">
$(function(){
var new_val = "anything" // Such as $("input#hidden_field_value").val()
$("input#hidden_field_id").val(new_val)
});
</script>
Upvotes: 2