mardi 2 février 2016

How to create/update an array using input checkboxes

In my view I am iterating through a collection of Customers called @colleagues and displaying them in a list as checkbox inputs like so:

<ol>
  <% @colleagues.each do |c|%>
    <li>
       <input type="checkbox">
           <%= c.full_name %>
           <%= c.id %>
       </input>
    </li>
  <% end %>
</ol>

What I wish to do is collect each checked/selected name in an array, which, on pushing of a button, will be sent to my controller. My question is, how can I create a dynamic array in javascript so that a colleague's id is added to the array or removed when unchecked?

Thanks




Aucun commentaire:

Enregistrer un commentaire