Hi, I was wondering if anyone can help me with this as I just don''t seem to figure out how I can refer to a combo box and change its selected value to another with a button click. Suppose a cambo box has values ''1'', ''2'', and ''3'' and I have a button "Next" and that currently ''1'' is selected in the combo box. So, when I click "Next" button I want it to select ''2'' and so on... Thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton
2008-Oct-10 01:28 UTC
Re: select another value in a combo box with a button click
Hi Jay, Jay Pangmi wrote:> > Hi, I was wondering if anyone can help me with this as I just don''t seem > to figure out how I can refer to a combo box and change its selected > value to another with a button click. > Suppose a cambo box has values ''1'', ''2'', and ''3'' and I have a button > "Next" and that currently ''1'' is selected in the combo box. So, when I > click "Next" button I want it to select ''2'' and so on...If I understand your question, one way I''ve done it is to put the combo box in a partial with the selected value ''fed'' and then use Ajax / RJS to re-render the partial as part of the "Next" action. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Oct-10 02:54 UTC
Re: select another value in a combo box with a button click
Jay Pangmi wrote:> Hi, I was wondering if anyone can help me with this as I just don''t seem > to figure out how I can refer to a combo box and change its selected > value to another with a button click. > Suppose a cambo box has values ''1'', ''2'', and ''3'' and I have a button > "Next" and that currently ''1'' is selected in the combo box. So, when I > click "Next" button I want it to select ''2'' and so on... > > Thanks. > -- > Posted via http://www.ruby-forum.com/.We can achieve the same effect purely on the client-side. Assuming your select dropdown is named "dropdown": <input type="button" value="Next" onclick="if($(''dropdown'').length - 1> $(''dropdown'').selectedIndex) $(''dropdown'').selectedIndex++;" />This requires Prototype, btw. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jay Pangmi
2008-Oct-10 04:16 UTC
Re: select another value in a combo box with a button click
Hi, guys thanks for all the help. Here''s how I have created the combo box: <%=select :camp, :id, @campsites_list%> So, how would I reference it and its a partial and its under _campsites.rhtml (partial file). Thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Oct-10 04:53 UTC
Re: select another value in a combo box with a button click
On Oct 10, 12:16 pm, Jay Pangmi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, guys thanks for all the help. Here''s how I have created the combo > box: > > <%=select :camp, :id, @campsites_list%> > > So, how would I reference it and its a partial and its under > _campsites.rhtml (partial file). > Thanks. > > -- > Posted viahttp://www.ruby-forum.com/.I still think that a client-side JS is better here, since IMHO an AJAX call just to select the next item of an already populated select dropdown is simply too much. <%= submit_tag "Next", :onclick => "if($(''camp'').length - 1 > $(''camp'').selectedIndex) $ (''camp'').selectedIndex++; return false;" %> --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jay Pangmi
2008-Oct-10 05:54 UTC
Re: select another value in a combo box with a button click
Erol Fornoles wrote:> <%= submit_tag "Next", > :onclick => "if($(''camp'').length - 1 > $(''camp'').selectedIndex) $ > (''camp'').selectedIndex++; return false;" %>Thanks Erol Fornoles for the answer.. but I just couldn''t make any use of it coz it doen''t work and I''m using <%=javascript_include_tag "prototype.js"%>. To make clear what I''m doing here is my code: VIEW: ===============================================================================<p> <label for = "walk location">Locations</label><br /> <%= select(:walks, :id, Greatwalk.find_available_locations, {:prompt=>''Select Great Walk Location''}, :selected => nil, :id => :great_walks) %> </p> <%= observe_field("great_walks", :url => {:controller => "user", :action => "update_campsites"}, :update => "campsites_list", :with => "id")%> <%form_for :cart, :url => {:action => :add_to_cart} do |form|%> <div id ="campsites_list" > <p> <label for = "camp location">Campgrounds</label><br /> <%= form.select "campsite", %w{ ---- }, :class => "select_campsites" %> </p> </div> <p> <label for = "arrival date">Arrival Date:</label><br /> <%= form.text_field :arrival_date %> </p> <p> <label for = "nights">Nights:</label><br /> <%= form.text_field :nights %> </p> <p> <label for = "parents">Parents:</label><br /> <%= form.text_field :parents %> </p> <p> <label for = "children">Children:</label><br /> <%= form.text_field :children %> </p> <p> <label for = "family claim">Family Rate:</label><br /> <%= form.check_box "family_claim",{}, "1", "0"%> </p> <%=submit_tag "Calculate"%> <%end%> <%= submit_tag "Next", :onclick => "if($(''camp'').length - 1 > $(''camp'').selectedIndex) $ (''camp'').selectedIndex++; return false;" %> =============================================================================== PARTIAL: ===============================================================================<p> <label for="camp location">Campgrounds</label><br/> <%=select "camp", "id", @resultset %> </p> =============================================================================== As you can see, I will be updating combo box in the partial. Also, what I want to do is make two buttons inside the form and if I click one it will change the value of combo box to next and if I click another some action will be call (add_to_cart in my case). Thanks again.. -- 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 -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Oct-10 06:39 UTC
Re: select another value in a combo box with a button click
On Oct 10, 1:54 pm, Jay Pangmi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> <p> > <label for="camp location">Campgrounds</label><br/> > <%=select "camp", "id", @resultset %> > </p>Where is the partial rendered? And when should it be rendered? I don''t see it in your main view. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jay Pangmi
2008-Oct-10 07:16 UTC
Re: select another value in a combo box with a button click
Erol Fornoles wrote:> On Oct 10, 1:54�pm, Jay Pangmi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> <p> >> � <label for="camp location">Campgrounds</label><br/> >> � <%=select "camp", "id", @resultset %> >> </p> > > Where is the partial rendered? And when should it be rendered? I don''t > see it in your main view.The file below is the partial which gets rendered in the <div> whose id is "campsites_list" in the view inside the <%form_for%> ... <%end%>. observe_field is observing the combo box with id :great_walks which is the first combo box in the view and updates the combo box inside the <%form_for%>..<%end%> inside <div> and this <div> is getting updated with the following partial file: _campsites.rhtml -------------------------------------------------------------------------------- <p> <label for="camp location">Campgrounds</label><br/> <%=select "camp", "id", @resultset %> </p> -------------------------------------------------------------------------------- thanks... -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Oct-10 08:09 UTC
Re: select another value in a combo box with a button click
On Oct 10, 1:54 pm, Jay Pangmi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks Erol Fornoles for the answer.. but I just couldn''t make any use > of it coz it doen''t work and I''m using <%=javascript_include_tag > "prototype.js"%>. To make clear what I''m doing here is my code:Try this instead: <%= submit_tag "Next", :onclick => "if($(''camp_id'').length - 1 > $ (''camp_id'').selectedIndex) $(''camp_id'').selectedIndex++; return false;" %> --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jay Pangmi
2008-Oct-10 10:04 UTC
Re: select another value in a combo box with a button click
Erol Fornoles wrote:> On Oct 10, 1:54�pm, Jay Pangmi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Thanks Erol Fornoles for the answer.. but I just couldn''t make any use >> of it coz it doen''t work and I''m using <%=javascript_include_tag >> "prototype.js"%>. To make clear what I''m doing here is my code: > > Try this instead: > > <%= submit_tag "Next", :onclick => "if($(''camp_id'').length - 1 > $ > (''camp_id'').selectedIndex) $(''camp_id'').selectedIndex++; return > false;" %>Thanks a tonn man... it works sweet. So, :camp, :id in the partial becomes ''camp_id'' and represents the combo box??? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Oct-10 10:19 UTC
Re: select another value in a combo box with a button click
On Oct 10, 6:04 pm, Jay Pangmi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks a tonn man... it works sweet. So, :camp, :id in the partial > becomes ''camp_id'' and represents the combo box??? > -- > Posted viahttp://www.ruby-forum.com/.Yeah, select :camp, :id generates a select tag with an id of "camp_id" and a name of "camp[id]". --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---