# Problems with :onchange for radio\_button\_tag

**URL:** <https://www.ruby-forum.com/t/problems-with-onchange-for-radio-button-tag/182166>\
**Category:** Rails\
**Created:** [January 23, 2010, 7:40pm UTC](https://www.ruby-forum.com/t/problems-with-onchange-for-radio-button-tag/182166 "2010-01-23T19:40:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuramonni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuramonni](https://www.ruby-forum.com/u/kuramonni)\
**Post date:** [January 23, 2010, 7:40pm UTC](https://www.ruby-forum.com/t/problems-with-onchange-for-radio-button-tag/182166/1 "2010-01-23T19:40:08Z")

</div>

Greetings,

I’ve been hitting my head to the wall over this for quite a while now  
and don’t seem to be able to wrap my forementioned head around it.  
Basically I have a list of users in a selection box and I have two radio  
buttons: Sort by first name and sort by last name. This is what I have  
in my view:

\<%= radio\_button\_tag ‘sort\_by\_last\_name’, ‘true’, :checked =\> true,  
:onchange =\> ‘#{remote\_function(:url =\> {:action =\>  
“update\_users”},  
:with =\> “order=1”)}’ %\> Sort by Last name  
  
\<%= radio\_button\_tag ‘sort\_by\_last\_name’, ‘false’,  
:onchange =\> ‘#{remote\_function(:url =\> {:action =\>  
“update\_users”},  
:with =\> “order=0”)}’ %\> Sort by First name

\<%= render :partial =\> 'users', :object =\> @users %\>

This is my partial view:  
\<%= collection\_select(nil, :user\_id, users, :id, :first\_name,  
{:prompt =\> “Select user”}) %\>

And this is my controller function for update\_users:

def update\_users  
if params[:order] == 1  
users = User.all  
else  
users = User.first  
end

render :update do |page|  
page.replace\_html ‘users’, :partial =\> ‘users’, :object =\> users  
end  
end

Now I’ve found a few sources describing on how this should be done, but  
I haven’t been able to get them to work for some unknown reason.
