Sharon Machlis
2008-Sep-02 00:29 UTC
Trying to fill in a couple of text fields based on user selection from a drop-down list
I''m *very* new working with Ajax. In a data submission form, I''d like some data to be filled in automatically (from the database) if a user selects certain options from a drop-down list. I have an Event model, and an Event submission form. If certain venues are selected on the form, I''d like to pre-populate the phone number and URL. So, if someone selects "Main Library" from the drop-down list, the library phone number and URL would up on the form. (The drop- down list is populated from my Venue model data). Here''s what I''ve tried without success. Any suggestions would be greatly appreciated. My submission view includes <div class="form_row"> <label for="venue_id">Place*:</label> <%collection_select(:event, :venue_id, @venues_all, :id, :name, {:prompt => " Please select a location"}) %> </div> <%= observe_field("venue_id", :frequency => 1, :url => { :controller => ''event'', :action => "venue_lookup" }, :with => "''id='' + value") %> <div class="form_row"> <label for="forinfo">Phone: </label><%= f.text_field :forinfo, :size => 50, :value => @user_phone %> </div> <div class="form_row"> <label for="url">Web site:</label> <%= f.text_field :url, :size => 50, :value => @user_url %> </div> And then my event controller includes def venue_lookup @venue = Venue.find(params[:id]) render :update do |page| page[:forinfo].value = @venue.contactinfo #this is in the database for venues in the drop-down list page[:url].value = @venue.url #this is in the database for venues in the drop-down list end end I''ve got mixed model input on the form, so I also tried def venue_lookup @venue = Venue.find(params[:id]) render :update do |page| page[:event_forinfo].value = @venue.contactinfo #this is in the database for venues in the drop-down list page[:event_url].value = @venue.url #this is in the database for venues in the drop-down list end end but that''s not working, and I can''t figure out why. Thanks. Sharon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---