I have a view in my Ruby on Rails application where there are two collect_selects on the right side, one of which is a list of users and the other a list of objects which has :multiple => true. When the user has selected a user and at least one object I want to display a chart on the right side with the user and whichever objects have been selected (likely using the gem Flot). I have seen how to get the selected object using selected_index, but I'm stumped as to how you can get an array of all of the selected objects when multiple selections are allowed. I was hoping to do everything in the javascript without having a submit button or anything, but is this possible?
Asked
Active
Viewed 452 times
1 Answers
0
I finally found my own answer. To get all of the selected objects in javascript, for example in a collection_select with id "user_id" you just need to use:
$("#user_id option:selected").each(function() {
// Do whatever with $(this).text() or $(this).val() for each option.
});

Alexei
- 127
- 13