# How can I use form fields in link\_to parameters?

**URL:** <https://www.ruby-forum.com/t/how-can-i-use-form-fields-in-link-to-parameters/107146>\
**Category:** Rails\
**Created:** [June 18, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/how-can-i-use-form-fields-in-link-to-parameters/107146 "2007-06-18T16:07:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gattox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@gattox](https://www.ruby-forum.com/u/gattox)\
**Post date:** [June 18, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/how-can-i-use-form-fields-in-link-to-parameters/107146/1 "2007-06-18T16:07:11Z")

</div>

Don’t know how to use a link\_to directive where one of the parameters  
is  
taken form a form field (client side), eg:

…

# 

# The field “numrows” is used to dynamically change the number of rows

per page

# in a pager (ok, let apart will\_paginate and other paginate plugins)

# 

#Rows per Page :   
\<%= text\_field\_tag “numrows”, session[:nr] ||  
Customer.per\_page, :size  
=\> 5 %\>  
\<%= link\_to ‘Change #Rows per Page’, {:action =\> ‘set\_row\_per\_page’,  
:rowsperpage =\> \<would like to pass here the content of “numrows”  
field\>, :method =\> :post, :class =\> “IsALink” %\>

Note that “numrows” is a non-model field of the form.

How can i dynamically set the value of “:rowsperpage” so that clicking  
on the link will restart pagination with a differente number of rows  
per page. I need to know how to dynamically set up the value of the  
parameter using something link $(‘numrows’).value

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![gattox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@gattox](https://www.ruby-forum.com/u/gattox)\
**Post date:** [June 18, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/how-can-i-use-form-fields-in-link-to-parameters/107146/2 "2007-06-18T17:27:22Z")

</div>

Hi gattox,

gattox wrote:

> Don’t know how to use a link\_to directive where one  
> of the parameters is taken form a form field (client side), eg:  
>   
> $(‘numrows’).value  
> I can’t think of any way to do this with link\_to. Remember that link\_to  
> is  
> a server-side helper method that’s generating an html \<a …\> tag to  
> send to  
> the client. There might be a way to use client-side javascript to  
> modify  
> the tag, but it doesn’t feel like a Rails-ish approach to me.

If it were me, I’d ditch the link-based submission and just use  
observe\_field on the text\_field or drop-down (select) to trigger the  
repagination action.

hth,  
Bill
