select onchange updates another select with remote_function
I use Rails 3.0.3
I've 2 <select>
, when the user choose an option in the first <select>
, the second should be updated. The onchange
event on the first select fire an ajax request to get the list(JSON format), the success
event call a function that transform the JSON to a list of <option>
to be inserted in the second <select>
.
Here the first <select>
<%= collection_select :brand, :category_id, Category.all, :id, :name, {}, {:onchange => "#{remote_function :url => brands_by_category_path(:category_id => ???), :success => "buildOptions(request, 'contract_brand_id')"}"} %>
the parameter of brands_by_category_path
(???) should be egal to the selected option of this <select>
I re开发者_开发知识库ally don't know how to achieve that?!!
Any idea?
Thanks
dont use this ugly inline stuff, with rails 3 (its supports 100% unobstructive javascript).
add a javascript tag after this and do this:
- get this select element by id
- set up an event listener for the change event
- add a call back to this event
- make sure the call does this:
brands_by_category_path(this.selected)
精彩评论