# React on select\_tag (onchange)

**URL:** <https://www.ruby-forum.com/t/react-on-select-tag-onchange/83385>\
**Category:** Rails\
**Created:** [January 25, 2007, 6:23pm UTC](https://www.ruby-forum.com/t/react-on-select-tag-onchange/83385 "2007-01-25T18:23:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mxmxmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mxmxmx](https://www.ruby-forum.com/u/mxmxmx)\
**Post date:** [January 25, 2007, 6:23pm UTC](https://www.ruby-forum.com/t/react-on-select-tag-onchange/83385/1 "2007-01-25T18:23:46Z")

</div>

Hi,

I’m new in developint rails (but I love rails).  
I would like to react on changing a field in the view (no model field)  
from a selection box to show the number of rows (which I used in the  
controller).

In the controller I read the params-hash:  
…  
@rowsperpage = params[‘rowsperpage’].to\_i  
…

In the view I have the field, where I like to react directly.  
…  
\<%= select\_tag(“rowsperpage”, options\_for\_select( [[5, 5], [10,10],  
[25,25], [50,50], [100,100],[200, 200],[500, 500],[1000, 1000]],  
@rowsperpage ),  
:onchange=\>“alert(this.form.rowsperpage.options[this.form.rowsperpage.selectedIndex].value)”  
) %\>  
…

The alert was only an example (I test it also with render, but without a  
solution).  
But I could change the values with no reaction.  
What must I do, that the controller react direcly on my changes.

Thanks in advance.  
Mike

---

<div class="post-metadata">

**Author:** ![mxmxmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mxmxmx](https://www.ruby-forum.com/u/mxmxmx)\
**Post date:** [January 25, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/react-on-select-tag-onchange/83385/2 "2007-01-25T19:07:33Z")

</div>

mx wrote:

> Hi,
> 
> I’m new in developint rails (but I love rails).  
> I would like to react on changing a field in the view (no model field)  
> from a selection box to show the number of rows (which I used in the  
> controller).
> 
> In the controller I read the params-hash:  
> …  
> @rowsperpage = params[‘rowsperpage’].to\_i  
> …
> 
> In the view I have the field, where I like to react directly.  
> …  
> \<%= select\_tag(“rowsperpage”, options\_for\_select( [[5, 5], [10,10],  
> [25,25], [50,50], [100,100],[200, 200],[500, 500],[1000, 1000]],  
> @rowsperpage ),  
> :onchange=\>“alert(this.form.rowsperpage.options[this.form.rowsperpage.selectedIndex].value)”  
> ) %\>  
> …
> 
> The alert was only an example (I test it also with render, but without a  
> solution).  
> But I could change the values with no reaction.  
> What must I do, that the controller react direcly on my changes.
> 
> Thanks in advance.  
> Mike

Try searching the web for keywords remote\_function and select\_tag

For example, this is close to what you want.

\<%= select\_tag( :sort\_by, options\_for\_select([[“Sort  
by:”,0],[“Name”,‘name’],[“Price”,‘price’], [“Date Listed”,‘id’]],0),  
:onchange =\> remote\_function( :with =\>  
“‘sort\_by=’+$(“sort\_by”).value”,  
:loading =\> “false;”,  
:url =\> { :controller =\> ‘products’, :action =\> :change\_order } )  
) %\>

Stephan
