Forum: Ruby on Rails React on select_tag (onchange)

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.
6b42aa84b01332f5e6a78c3f54261d36?d=identicon&s=25 mx (Guest)
on 2007-01-25 18:23
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
72ea925c0ca3d19fdd2f12fa76681624?d=identicon&s=25 Stephan Wehner (stephanwehner)
on 2007-01-25 19:07
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
This topic is locked and can not be replied to.