Event Listeners for form > select tags

How do you attach an event listener to watch for the user to change the
selected option in a ‘select’ field before they click the submit button
in order to instruct the page to change (AJAX) based on what the user
selected in the field. In other words, I want the page to be able
to change when the user makes a selection from a form select before they
ever click any button.

Thank you.

Sam

Sam W. wrote:

How do you attach an event listener to watch for the user to change the
selected option in a ‘select’ field before they click the submit button
in order to instruct the page to change (AJAX) based on what the user
selected in the field. In other words, I want the page to be able
to change when the user makes a selection from a form select before they
ever click any button.

Check out the observe_field method in
ActionView::Helpers::PrototypeHelper
In: vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb

Raja Venkataraman wrote:

In: vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb


Posted via http://www.ruby-forum.com/.

Take a look at this…

http://www.sciwerks.com/blog/2006/07/07/updating-select-controls-with-ajax/

_Kevin

_Kevin wrote:

Raja Venkataraman wrote:

In: vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb


Posted via http://www.ruby-forum.com/.

Take a look at this…

http://www.sciwerks.com/blog/2006/07/07/updating-select-controls-with-ajax/

_Kevin

I can’t get this plugin to work. I installed it and then wrote method:

def on_prebooking_start_date_change
render :update do |page|
@current_two_months = two_months_starting(
params[:dom_value].month, params[:dom_value].year)
page.replace_html( “month_1”, :partial => “month”, :object =>
@current_two_months )
end
end

With the following view code:

_rent.rhtml:

<%= render(:partial => “month” , :object => @current_two_months) %>
<%= start_form_tag :action => ‘start_date’ %>
<%= render(:partial => “prebooking_dates_selects”) %>
<%= submit_tag “Check Rate >” %>
<%= end_form_tag %>

_month.rhtml:

...month 1 view html here...

and _pre_booking_dates_selects.rhtml:

Start Date
<%= date_select 'prebooking', 'start_date', :id => 'start_date', :start_year => 2007, :end_year => Day.last_day.year, :order => [:month, :day, :year] %>

The on…change method above does nothing. ???

Sam

I even tried

def on_prebooking_start_date_change
render :update do |page|
page.insert_html(:after, ‘start_date’, :inline => “This is
working
” )
end
end

Just to see if it worked.

It doesn’t!

Sam