Pass data from a table html to mysql from jsp

1

Greetings, I appreciate your kind support. I have a form to register products that are added to the table but I have no idea how to send them to mysql dede JSP .

<form  id="detalle_boleta" class="form-horizontal" method="get" 
 action="Detalle_Ventas" role="form" autocomplete="off">     
     <div class="row">
 <!--Inicia Definicion Table -->                               
      <script type="text/javascript">
             $(document).ready(function () {
             $("#mytable").tablesorter();
              });
        </script>
    <h3>Detalle de Venta.</h3>
       <table class="tablesorter" id="mytable">
            <thead>
                <tr>
                    <th>Fecha</th>
                    <th>Producto</th>
                    <th>Precio</th>
                    <th>Cantidad</th>
                    <th>Total</th>

                </tr>
            </thead>
            <tbody data-bind="foreach: detalle_ventas ">
                <tr>
                    <td data-bind="text:$data.fecha"> </td>
                   <td data-bind="text:$data.producto"> </td>
                    <td data-bind="text:$data.precio"> </td>
                    <td data-bind="text:$data.cantidad"> </td>
                    <td data-bind="text:$data.total"> </td>


                </tr>

            </tbody>
        </table>
     </div>   
      </form>
 </div>         

<script type="text/javascript">
        function DetalleBoleta() {
            var self = this;

            //vector que guardara la informacion temporalmente 
             self.detalle_ventas = ko.observableArray([]);

            self.agregarproducto = function (){

                var fe = $('#txtfecha').val();
                 var pro = $('#cbxproducto').val();
                var pre = parseFloat($('#txtprecio').val());
                var cant = parseInt($('#txtcantidad').val());
                var tot=pre * cant;

                 alert("Producto Agregado");  
             self.detalle_ventas.push({fecha:fe, producto:pro, precio:pre, cantidad:cant,total:tot});


            };
             }
        ko.applyBindings(new DetalleBoleta());
    </script>
    
asked by Victor Perales 14.12.2017 в 23:55
source

2 answers

1

good we use the function each of jquery and for each iteration of tr we create a array that at the end we add with the method push and fill with each value within the td .

Functional example

$("#obtenerDatos").click(function(){
  var mytabla = []
  $("#mytable").find("tbody tr").each(function(index, el) {
    var tr = []
    $(this).find("td").each(function(index, el) {
       tr.push($(this).text())
    });
    mytabla.push(tr)
  });
  console.log(mytabla);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="tablesorter" id="mytable">
            <thead>
                <tr>
                    <th>Fecha</th>
                    <th>Producto</th>
                    <th>Precio</th>
                    <th>Cantidad</th>
                    <th>Total</th>

                </tr>
            </thead>
            <tbody data-bind="foreach: detalle_ventas ">
                <tr>
                    <td data-bind="text:$data.fecha">Valor 1</td>
                   <td data-bind="text:$data.producto">Valor 2</td>
                    <td data-bind="text:$data.precio">Valor 3</td>
                    <td data-bind="text:$data.cantidad">Valor 4</td>
                    <td data-bind="text:$data.total">Valor 5</td>
                </tr>
                <tr>
                    <td data-bind="text:$data.fecha">Valor 6</td>
                   <td data-bind="text:$data.producto">Valor 7</td>
                    <td data-bind="text:$data.precio">Valor 8</td>
                    <td data-bind="text:$data.cantidad">Valor 9</td>
                    <td data-bind="text:$data.total">Valor 10</td>
                </tr>
            </tbody>
        </table>
        <button id="obtenerDatos" type="button" name="button">Obtener datos de Tabla</button>

I hope you help greetings.

    
answered by 15.12.2017 / 02:12
source
0

Excellent help me, now I have those captured in the table but as a send to the mysql database

    
answered by 15.12.2017 в 05:20