Use AJAX for onchange of a SELECT box

Here’s how to use AJAX from the onchange event of the SELECT element :

I used an extra ERB step in my view in order to reduce chaos being created by double quotes. This example actually triggers two AJAX calls on the event to update different targets (two cascaded SELECTs).

 :model_select,
                    :url => { :action => :ajax_list_model_select },
                    :with=> " 'project_id='+value") + ";" +
                 remote_function(:update => :category_select,
                    :url => { :action => :ajax_list_category_select },
                    :with=> " 'project_id='+value")
                 %>

 onchange_ajax } ) %>

The result has the SELECT element with onchange=”new Ajax.Updater…”

Joy!