I have 2 tables: Products and Services. I have added products and services to cart functions as rows.
So on each click on trash image, I need to pass as an product and service ids as an array.
<% @service_appointment_operation.each do |sao| %>
<tr style="color: #e06d6d;" data-tt-parent-id="ser_<%= @service_appointment.id %>" data-tt-id="ser_<%= @service_appointment.id %>_<%= sao.operation.id %>">
<td><span class="glyphicon glyphicon-trash" onclick="deleteRow(<%=service_appointment.id%>,'<%= sao.operation_type %>')"></span></td>
</tr>
<% end %>
JavaScript function:
function deleteRow(id,type) {
var operation_type = type;
if (operation_type == "Service") {
$('#deleted_service_ids').val(id);
} else {
$('#deleted_product_ids').val(id);
}
}
Form Hidden fields
<%= hidden_field_tag "deleted_product_ids[]", "", id: "deleted_product_ids" %>
<%= hidden_field_tag "deleted_service_ids[]", "", id: "deleted_service_ids" %>
Now I am getting params as one product id, one service id. How can I pass ids as an array if I delete more than one product and service? How can I pass values of products and services as an array to hidden field?