# RoR AJAX select box update?

**URL:** <https://www.ruby-forum.com/t/ror-ajax-select-box-update/51844>\
**Category:** Rails\
**Created:** [January 8, 2006, 4:51am UTC](https://www.ruby-forum.com/t/ror-ajax-select-box-update/51844 "2006-01-08T04:51:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Sandosh](https://www.ruby-forum.com/u/Sandosh)\
**Post date:** [January 8, 2006, 4:51am UTC](https://www.ruby-forum.com/t/ror-ajax-select-box-update/51844/1 "2006-01-08T04:51:05Z")

</div>

Hi,

I want to update a select box depending on another selected option thru  
ajax.

Heres how I do it

# \_form.rhtml

\<select id=“budget\_coordinator\_id” name=“budget[coordinator\_id]”  
onchange="\<%= remote\_function(:update =\> “budget\_project\_number”, :url  
=\> { :action =\> :get\_projects }) %\>"\>  
\<%= options\_from\_collection\_for\_select(Coordinator.find\_all, “id”,  
“coordinator\_name”) %\>

#get\_projects  
def get\_projects  
@results = Project.find\_all  
render :partial =\> ‘options’  
end

# \_options.rhtml

\<% for project in @results do -%\>

\<%=project.project\_number%\> \<% end -%\>

This somehow seem to work in firefox, but not in IE. also the ajax calls  
returns the whole options tag… instead of this, can we just return the  
result object and then populate the select on the client side?

Advanced Thanx for any help!

Sandosh

---

<div class="post-metadata">

**Author:** ![Sandosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Sandosh](https://www.ruby-forum.com/u/Sandosh)\
**Post date:** [January 8, 2006, 11:32am UTC](https://www.ruby-forum.com/t/ror-ajax-select-box-update/51844/2 "2006-01-08T11:32:46Z")

</div>

On 1/7/06, Sandosh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> onchange="\<%= remote\_function(:update =\> “budget\_project\_number”, :url  
> #get\_projects  
> \<% end -%\>
> 
> This somehow seem to work in firefox, but not in IE. also the ajax calls  
> returns the whole options tag… instead of this, can we just return the  
> result object and then populate the select on the client side?

Let me know if you find out the answer… I’d also like to know this.

---

<div class="post-metadata">

**Author:** ![Sandosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Sandosh](https://www.ruby-forum.com/u/Sandosh)\
**Post date:** [January 9, 2006, 4:56am UTC](https://www.ruby-forum.com/t/ror-ajax-select-box-update/51844/3 "2006-01-09T04:56:11Z")

</div>

This has been asked many times and I think the best resource so far is  
Rory  
Hansen’s "Rory on Rails " article.  
[http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)  
It is actually quite simple if you learn to use the link\_to\_remote and  
the  
observe\_field macros or better still master the prototype library and  
use  
Javascript directly.
