Accessing the selected item select_tag

Well, I have multiple select_tags (values ​​are generated from a split single row):

<% @item.item_options.each do |x| %>
    <% if !x.value.empty? && !x.option.empty? %>
    <div class="row"> <%= x.option %> : <%= select_tag :values, options_for_select(x.value.split(',')) %></div>
    <% end %>
<% end %>

      

I am trying to concatenate only selected values ​​from each into one line. And separate them with a spatial symbol and pass it to another controller.

I am using hidden_filed to send values, but I cannot access the selected values ​​to perform concatenation!

<%= f.hidden_field :values, :value => ??? %> 

      

+3


source to share


1 answer


You can use jquery to get the selected value of the select:

$('select option:selected').val();

      

If I understand your question correctly.



To get all selected items of items from all select items take a look here:

Get all selected item elements from all select items on a form

0


source







All Articles