# Updating a form.select based whenever another form.select change \[ajax\]

**URL:** <https://www.ruby-forum.com/t/updating-a-form-select-based-whenever-another-form-select-change-ajax/177121>\
**Category:** Rails\
**Created:** [October 12, 2009, 1:26am UTC](https://www.ruby-forum.com/t/updating-a-form-select-based-whenever-another-form-select-change-ajax/177121 "2009-10-12T01:26:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [October 12, 2009, 1:26am UTC](https://www.ruby-forum.com/t/updating-a-form-select-based-whenever-another-form-select-change-ajax/177121/1 "2009-10-12T01:26:53Z")

</div>

I have the following form :

\<% form\_for :registration, @registration, :url =\> { :action =\>  
“create” } , :html =\> {:class =\> ‘generalform’} do |form| %\>  
\<%= render :partial =\> “form”, :object =\> form %\>  
\<%= form.submit “Register”, :class =\> ‘go’ %\>&nbsp;\<%= link\_to  
‘Cancel’, registrations\_path %\>  
\<% end %\>

with this partial : (2 form select)

 \<%= form.label :trainee %\>  
 \<%= form.select(:trainee\_id, @trainees.map {|s| [s.name, s.id]}, {:include\_blank =\> '- select a trainee -' }, :style =\> "width: 200px;", :onchange =\> remote\_function( :method =\> "post", :with =\> "'trainee\_id=' + value", :url =\> choose\_registrations\_path ) )%\> 

 \<%= form.label :educational\_path %\>  
 \<%= form.select(:epath\_id, @epaths.map {|g| [g.kp\_path\_name, g.id]}, {:include\_blank =\> '- select an educational path -' }, :style =\> "width:200px;" ) %\> 

whenever the first select change (trainee) an Ajax request is fired  
(remote\_function) and the choose action in controller registrations is  
executed … working well , based on the trainee \_id , an array  
@epaths should be displayed in the second form.select…

I I put the second select in a partial, I loose the form

should I write ALL the form in a select a refresh it, or can I refresh  
only the 2 select ?

thanks for your help

erwin
