开发者

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:

  1. get this select element by id
  2. set up an event listener for the change event
  3. add a call back to this event
  4. make sure the call does this: brands_by_category_path(this.selected)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜