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"}) %>

    <%= observe_field("venue_id",
                      :frequency => 1,
                      :url => { :controller => 'event', :action =>

“venue_lookup” },
:with => “‘id=’ + value”) %>

Phone: <%= f.text_field :forinfo, :size => 50, :value => @user_phone %>
Web site: <%= f.text_field :url, :size => 50, :value => @user_url %>

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs