On Thu, Jan 22, 2009 at 9:13 AM, Tony Tony <rails-mailing-l...@andreas-s.net > wrote:
> > Hi all, > > I'm having a hard time trying to find a good tutorial on how to generate > a field (with ajax) from a dropdown selection. > > For example: > > I have an app where you can select up to two tickets per person. Only if > the user selects '2' from the dropdown menu should a field pop > up/generate below the dropdown and ask the user for the name of the > second person. > > So far I have the following code: > > <h3>Number of Tickets?</h3> > <%= select :tickets, :quantity, { "Select quantity" => "", "1" => "1", > "2" => "2"} %> > > <h3>Name of guest?</h3> > <%= f.text_field :guest_name %> > > > So in my case, only if quantity is selected as two should guest_name > appear (without refreshing the page). > > > Thanks in advance and THANK YOU FOR YOUR TIME!! > I was looking for an answer to much the same question not too long ago. I found all sorts of tutorials showing how to populate a 2nd drop down menu based upon the contents of the first (such as http://pullmonkey.com/2008/3/30/dynamic-select-boxes-ruby-on-rails). Ultimately, I was able to learn enough from reading those to learn that (in your case) I would want to put a blank <div> tag in my layout where I would want the "name of guest" stuff to appear, and to populate the "name of guest" stuff only when quantity == 2. I hope this helps. --wpd --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---