Forum: Ruby on Rails RoR AJAX select box update?

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.
Eafb60be69abc8878474d48c5eb28f64?d=identicon&s=25 Sandosh (Guest)
on 2006-01-08 04:51
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") %>
</select>


<select id="budget_project_number" name="budget[project_number]">
</select>


#get_projects
def get_projects
   @results = Project.find_all
   render :partial => 'options'
end


# _options.rhtml
<% for project in @results do -%>
<option
value="<%=project.project_id%>"><%=project.project_number%></option>
<% 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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-01-08 11:32
(Received via mailing list)
On 1/7/06, Sandosh <sandoshvr@yahoo.com> 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.
6828ffc79486cd2442714bf32286a910?d=identicon&s=25 Vivek Krishna (Guest)
on 2006-01-09 04:56
(Received via mailing list)
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
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.
This topic is locked and can not be replied to.