Add row to a table

1

I have a problem with a table, I want to add rows in a table with JQuery. At the time of adding and deleting the rows everything is fine, but when you save these rows in a database they are saved in a single record. For example: When saving 5 rows of products, all 5 rows are saved in a single field of the database.

Could you help me please?

  

<script>
    $(document).ready(function () {
        $("#nuevalinea").click(function () {
            var clonarfila = $("#tablaresponsive").find("tbody tr:last").clone();
            $("table tbody").append(clonarfila);
        });

        $("#tablaresponsive").on('click', '.eliminalinea', function () {
            var numeroFilas = $("#tablaresponsive tr").length;
            if (numeroFilas > 2) {
                $(this).closest('tr').remove();
            }
        });
    });

</script>
<table class="table table-bordered" id="tablaresponsive">
  <thead>
    <tr>
      <%--<th><input type="checkbox" id="check-all" class="flat"></th>--%>
      <th>Producto</th>
      <th>Cantidad Canjes</th>
      <th>Factura</th>
      <th>Fecha Factura</th>
      </tr>
    </thead>
    <tbody>
      <tr>
       <td><%--<input type ="number" name="Producto[]" class="form-control">--%><asp:TextBox ID="TextBox5" type ="number" name="Producto[]" class="form-control" runat="server"></asp:TextBox></td>
       <td>
         <input type ="number" name="Cantidad Canjes[]" class="form-control">
        </td>
        <td>
          <input type ="number" name="Factura[]" class="form-control">
        </td>
        <td><input type ="number" name="Fecha Factura[]" id="textboxfila"  class="form-control"></td>
	
        
      
        <td><button type="button" class="eliminalinea">eliminar</button></td>
     </tr>
     </tbody>
</table>

    <tr>
     
      <th>Producto</th>
      <th>Cantidad Canjes</th>
      <th>Factura</th>
      <th>Fecha Factura</th>
      </tr>
    </thead>
    <tbody>
      <tr>
       <td><asp:TextBox ID="TextBox5" type ="number" name="Producto[]" class="form-control" runat="server">

           </asp:TextBox></td>
       <td>
         <input type ="number" name="Cantidad Canjes[]" class="form-control">
        </td>
        <td>
          <input type ="number" name="Factura[]" class="form-control">
        </td>
        <td><input type ="number" name="Fecha Factura[]" id="textboxfila"  class="form-control"></td>
	
        
      
        <td><button type="button" class="eliminalinea">eliminar</button></td>
     </tr>
     </tbody>
</table>
<button type="button" id="nuevalinea" class="btn btn-danger"><span class="glyphicon glyphicon-plus"></span> FILA</button>
</div>
    
asked by MIGUEL SUERO 07.11.2017 в 18:38
source

1 answer

0

If the error is in "save in the database" you should check the code stored in the database. Most likely, you will have to iterate between the arrays of received fields to create an insert / update for each row.

Here is an example in PHP: link

    
answered by 29.03.2018 в 15:48