Forum: Ruby on Rails getting value of hidden field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lalala L. (Guest)
on 2007-04-09 12:13
hi
in my rhtml file i have

<form name="par2">
<%= hidden_field_tag 'fc', 42, :id=>'fc' %>
</form>

how can i set params[:blah] to have the value of fc, so i can access the
value of fc through params[:blah] in my controller ?

thank you
Francis S. (Guest)
on 2007-04-09 12:20
Lalala L. wrote:
> hi
> in my rhtml file i have
>
> <form name="par2">
> <%= hidden_field_tag 'fc', 42, :id=>'fc' %>
> </form>
>
> how can i set params[:blah] to have the value of fc, so i can access the
> value of fc through params[:blah] in my controller ?
>
> thank you

well, you have to change this:

<%= hidden_field_tag 'blah', 42, :id=>'fc' %>

to access it as params[:blah] in your controller.

Hope that helps:)
Lalala L. (Guest)
on 2007-04-09 21:15
Francis S. wrote:
> Lalala L. wrote:
>> hi
>> in my rhtml file i have
>>
>> <form name="par2">
>> <%= hidden_field_tag 'fc', 42, :id=>'fc' %>
>> </form>
>>
>> how can i set params[:blah] to have the value of fc, so i can access the
>> value of fc through params[:blah] in my controller ?
>>
>> thank you
>
> well, you have to change this:
>
> <%= hidden_field_tag 'blah', 42, :id=>'fc' %>
>
> to access it as params[:blah] in your controller.
>
> Hope that helps:)

<form name="par2">
<%= hidden_field_tag 'fc1', 42, :id=>'fc2' %>
</form>
what if I want to fill the value using javascript? Let's say instead of
42, I want the return value of js() to be the value of this hidden
field. Is there a way of doing this?

Usually using javascript I can access a hidden field value using:
document.formName.fieldName.value. Please correct me, in this case the
formName = par2 and what is the fieldName ? Is it fc1 or fc2?
Let's say it is fc1, when I do document.par2.fc1.value = 12, Will 12 be
the value of params[:fc1] in my controller?

I come up to this question because I want to pass value from javascript
to ruby, and thinking that I can just put the javascript value to hidden
field and let rails grab the value from hidden field

Thank you for replying
This topic is locked and can not be replied to.