# Select helper

**URL:** <https://www.ruby-forum.com/t/select-helper/134178>\
**Category:** Rails\
**Created:** [April 8, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/select-helper/134178 "2008-04-08T17:13:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [April 8, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/select-helper/134178/1 "2008-04-08T17:13:34Z")

</div>

I have this form which is a lot of edit\_in\_place fields so it really  
insn’t a form since there is no submit button. In this “form” is a link  
for a country and when you click that a drop down appears in it’s place  
and a country can be choosen, when that country is chossen the drop  
downs turns back into a link with the newly choosen country as the text.  
I had this working before by using options\_from\_collection\_for\_select  
and adding an onchange and setting it equal to a remote\_function call.  
That worked. But now I would like for a particular country to be choosen  
by default but with the same functionality. So I changed my code and  
used a select helper:

\<% func = remote\_function( :update =\> ‘w\_country’, :url =\> { :action =\>  
‘set\_w\_country’, :id =\> @user.id}, :with =\> “‘select=’ +  
escape(value)” ) -%\>

\<%= select( “user”, “w\_country”, Countrycode.find( :all, :order =\>  
‘country’ ).collect { |a| [a.country, a.id]},  
:selected =\> Countrycode.find\_by\_country(‘USA’).id, :onchange =\>  
func ) %\>

Now it selects the correct default country but my remote\_function never  
gets called or executed. I think what is happening is that I don’t have  
the helper set up correctly - more specifically the :onchange. Does  
anyone know how to add the onchange part to the select helper and to  
have a certain entry set as the default? Thanks for any and all help,

-S
