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 -- Posted via http://www.ruby-forum.com/.
On 1/7/06, Sandosh <sandoshvr@yahoo.com> wrote:> 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?Let me know if you find out the answer... I''d also like to know this.
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. On 1/8/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> > On 1/7/06, Sandosh <sandoshvr@yahoo.com> wrote: > > 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? > > Let me know if you find out the answer... I''d also like to know this. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060109/1ecb9d47/attachment.html
Apparently Analagous Threads
- [libopusfile PATCH] build: implement autotools build system for libopusfile. (v4)
- Building a view for a 3 model has_many relationship
- Rails 3 Foreign Domain routing - cannot get this to work!
- Help with error
- Nested Resouces,not getting parent id(project_id) from form