Hi, I''m trying some RJS to update a series of list boxes in which the user selects a state, and the following list gets updated with a list of counties, and the same for the next list of areas. My code works perfectly (albeit a bit slow) on Firefox, but on Internet Explorer it clears the list box (instead of filling it) and Netscape shows all the counties cramped together on one <option> instead of multiple options. This is the relevant code from the form: <select id="area_county_id" name="address[area_id]"><option value="0">Select a state</option></select> <select id="address_area_id" name="address[area_id]"><option value="0">Select a county</option></select> <%= observe_field "county_state_id", :url => {:action => ''update_counties_list''}, :with => ''county_state_id'' %> <%= observe_field "area_county_id", :url => {:action => ''update_areas_list''}, :with => ''area_county_id'' %> And on the controller: def update_counties_list render :update do |page| if params[''county_state_id''].blank? page.replace_html ''address_area_id'', ''<option>Select a county</option>'' page.replace_html ''colonia_municipio_id'', ''<option>Select a state</option>'' else @state = State.find params[''county_state_id''], :include => ''counties'' page.replace_html ''area_county_id'', ''<option></option>'' + options_from_collection_for_select(@state.counties, ''id'', ''name'') end end end Upon inspecting HTTP traffic it seems the JavaScript code is fine (it works on Firefox after all), and neither IE nor Netscape show any error whatsoever. Weird thing is, on IE, if I open the RJS URL directly, sometimes it works (showing the JS code), sometimes it doesn''t, showing an error message saying it can''t download the url (the requested site is either unavailable or cannot be found). I''m on edge #4716 and I''ve tested on IE 6 & 7 beta 3. I hope someone can help me :( Kind regards, Ivan V. -- Posted via http://www.ruby-forum.com/.
why not try using an onchange handler in your select list, rather than observe_field: <select id="user_country_id" name="user[country_id]" onchange="<%= remote_function( :update => ''locality'', :url => { :action => :change_country }, :with => "''user_country='' + $F(''user_country_id'')") %>"> <%= options_from_collection_for_select(@countries, ''id'', ''country_name'', @locality.id ) %> </select> Mike On 8/10/06, Ivan V. <creador@omnipotente.com> wrote:> Hi, > > I''m trying some RJS to update a series of list boxes in which the user > selects a state, and the following list gets updated with a list of > counties, and the same for the next list of areas. > > My code works perfectly (albeit a bit slow) on Firefox, but on Internet > Explorer it clears the list box (instead of filling it) and Netscape > shows all the counties cramped together on one <option> instead of > multiple options. > > This is the relevant code from the form: > > <select id="area_county_id" > name="address[area_id]"><option value="0">Select a > state</option></select> > <select id="address_area_id" > name="address[area_id]"><option value="0">Select a > county</option></select> > <%= observe_field "county_state_id", :url => {:action => > ''update_counties_list''}, :with => ''county_state_id'' %> > <%= observe_field "area_county_id", :url => {:action => > ''update_areas_list''}, :with => ''area_county_id'' %> > > And on the controller: > > def update_counties_list > render :update do |page| > if params[''county_state_id''].blank? > page.replace_html ''address_area_id'', ''<option>Select a > county</option>'' > page.replace_html ''colonia_municipio_id'', ''<option>Select a > state</option>'' > else > @state = State.find params[''county_state_id''], :include > => ''counties'' > page.replace_html ''area_county_id'', ''<option></option>'' > + options_from_collection_for_select(@state.counties, ''id'', ''name'') > end > end > end > > Upon inspecting HTTP traffic it seems the JavaScript code is fine (it > works on Firefox after all), and neither IE nor Netscape show any error > whatsoever. > > Weird thing is, on IE, if I open the RJS URL directly, sometimes it > works (showing the JS code), sometimes it doesn''t, showing an error > message saying it can''t download the url (the requested site is either > unavailable or cannot be found). > > I''m on edge #4716 and I''ve tested on IE 6 & 7 beta 3. > > I hope someone can help me :( > > Kind regards, > Ivan V. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Peter De Berdt
2006-Aug-13 13:08 UTC
[Rails] RJS in Internet Explorer to update a list box
On 10 Aug 2006, at 18:09, Ivan V. wrote:> Weird thing is, on IE, if I open the RJS URL directly, sometimes it > works (showing the JS code), sometimes it doesn''t, showing an error > message saying it can''t download the url (the requested site is either > unavailable or cannot be found). > > I''m on edge #4716 and I''ve tested on IE 6 & 7 beta 3. > > I hope someone can help me :(IE goes wonky when trying to replace in the inner elements of <select> tags. You''ll be better off replacing either the whole <select> using page.replace instead of page.replace_html or just wrapping the select itself in a div or span element, so you can use that in your page.replace_html. This last method works, I''m using it in one of my apps. It''s not really the ideal solution for semantic XHTML markup, but sometimes you need to bend the rules a bit if that makes it work on all browsers. Also, instead of rendering your element in your controller, use a render :partial passing an object (so you can use the name of the partial as a variable, all selects can be rendered using the same partial), your code would be a lot more DRY. Best regards Peter De Berdt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060813/db5ade7d/attachment.html
Senthil Krishnamoorthy
2007-Jan-31 10:02 UTC
Re: RJS in Internet Explorer to update a list box
Hi mike, could you please explain the flow in detail for the below, I am new to ruby on rails. And also i explained my requirement. i have a table called "locations" which holds the fields location_code and location_name. And i displayed that location_name in list box. Also i have another table called "userdetails" which has field called country_code. I want to update the country_code in "userdetails" table based on the selection of list box it fetches the location_code.> > <select id="user_country_id" name="user[country_id]" > onchange="<%= remote_function( :update => ''locality'', :url => { > :action => :change_country }, :with => "''user_country='' + > $F(''user_country_id'')") %>"> > <%= options_from_collection_for_select(@countries, ''id'', > ''country_name'', @locality.id ) %> > </select> >regards Senthil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ivan V. wrote:> Hi, > > I''m trying some RJS to update a series of list boxes in which the user > selects a state, and the following list gets updated with a list of > counties, and the same for the next list of areas. > ....I''ve posted some days ago (http://www.ruby-forum.com/topic/95361#196262) a code that replaces, using RJS, select option values. See if it can be useful for you. page[''field_id''].length=0 @your_object.each do |obj| page << "$(''field_id'').options[$(''field_id'').length]=new Option(''#{escape_javascript(obj.to_s)}'',#{obj.id})" end Regards Massimo http://www.addsw.it -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Massimo, I am updating the value in some other way, which seems to be quite simple. in controller: @object=classname.find(:all).map {|l| [l.field_name, l.field_code]} in view: <label for="object2_field_name">Country</label> <%= select(:object2, :field_code, @object1) %> here object1 is a parent table and object2 is a child table. based the change of the value in object1 the object2 will get updated. Now problem is different the i want display the value for the selection in seperate text field. ie., how to get the code for the selected name. regards Senthil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---