Skip to content

Instantly share code, notes, and snippets.

@hernandezalek
Created June 5, 2019 15:43
Show Gist options
  • Save hernandezalek/f15c760e887d6b6eb17a59198d256ca8 to your computer and use it in GitHub Desktop.
Save hernandezalek/f15c760e887d6b6eb17a59198d256ca8 to your computer and use it in GitHub Desktop.
Table Inputs
<table>
<thead>
<tr>
<th width="350px">Producto/Servicio</th>
<th>Cantidad</th>
<th>Precio</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<%= form.fields_for :output_items , id: "multiplicar" do |output_item| %>
<tr>
<td><%= output_item.collection_select :item_id, Item.all, :id, :name, { :include_blank => "Seleccionar item" } %></td>
<td><%= output_item.number_field :quantity, class: "quantity", onChange: "multiplicar();" %></td>
<td><%= output_item.number_field :price, class: "price", onChange: "multiplicar();" %></td>
<td><input type="text" disabled="true" id="total" ></td>
</tr>
<% end %>
</tbody>
</table>
<script>
function multiplicar(){
input1 = document.querySelector(".quantity").value;
input2 = document.querySelector(".price").value;
total = parseInt(input1)*parseInt(input2);
document.getElementById("total").value = total;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment