Select id dynamics

1

I have a form that I fill with data of a product. I need to know how I can work with dynamic ids, searching the Internet I learned that brackets should be added at the end of the id in this way: name="id[]" but my problem is that no I know how to call them in the jquery selector. At the moment of selecting a button of the desired product the information of that product is requested and I filled my td e input corresponding in the following way:

var cant = prompt("Ingresar Cantidad:");

if(cant>0){
$('#cod[]').val(data.ID); //probé con esto pero no me dio resultado

Before dealing with the problem of adding the data to the corresponding table, I worked on it in this way, increasing a variable by 1

var $cant = $('#qty'+idqty).text(cant);
idqty ++;
$('#producto'+idprod).text(data.DESC);
idprod ++;
$('#precio'+idpre).val(data.PRECIO);
idpre ++;
agrega_fila();
calcular_valores(cant,data.PRECIO);

}else{
    alert ("La cantidad debe ser mayor a 0");
}

The problem is that I have no idea how to insert the data in the way it works (increase the variable with each iteration)

Form code:

<div class="col-md-8">
                <div class="contenido">
                        <h3>Detalle</h3>
                        <form id="detalle-form" method="post" class="form-horizontal style-form" >
                            <input id="n-mesa" name="n-mesa" hidden="" type="number"></th>

                          <table class="table table-fixed" id="pedido">
                          <thead>
                             <tr>
                             <th class="col-xs-2">Codigo</th>
                              <th class="col-xs-2">Qty</th>
                              <th class="col-xs-2">Descripción</th>
                              <th class="col-xs-3">Peso</th>
                              <th class="col-xs-3">Precio</th>
                            </tr>
                          </thead>
                            <tr id="fila0">
                                <td class="col-xs-2">
                                         <div class="input-group"><input id="cod[]" class="form-control input-md"  type="text"></div>
                                 </td>
                                <td class="col-xs-2" id="qty0"></td>
                                 <td class="col-xs-2" id="producto0"></td>
                                 <td class="col-xs-3">
                                         <div class="input-group"><div class="input-group-addon">Kg</div><input id="peso0" class="form-control input-md"  type="text" value="0"></div>
                                 </td>
                                 <td class="col-xs-3">
                                         <div class="input-group"><div class="input-group-addon">$</div><input id="precio0" class="form-control input-md"  type="text" value="0"></div>
                                 </td>
                            </tr>
                             <tfoot>
                             </table>
                             <table class="table">
                             <tr >
                              <td  class="col-xs-3"></td>
                                  <td class="col-xs-3"></td>
                                  <td class="col-xs-3">Total :</td>
                                  <td class="col-xs-3">
                                     <div class="input-group"><div class="input-group-addon">$</div><input id="total" class="form-control input-md"  type="text" value="0"></div>
                                 </td>
                            </tr>
                            <tr>
                              <td  class="col-xs-3"><button title="Guardar registro" id="save" name="save" class="btn btn-success"><span class="glyphicon glyphicon-floppy-disk"></span></button>
                                                    <button class="btn btn-success "><span class="glyphicon glyphicon-print"></span></button>
                              </td>
                                  <td class="col-xs-3"></td>
                                  <td class="col-xs-3">Propina Sugerida 10% </td>
                                  <td class="col-xs-3">
                                     <div class="input-group"><div class="input-group-addon">$</div><input id="propina" class="form-control input-md"  type="text" value="0"></div>
                                 </td>
                            </tr>

                        </table>
                  </form>
    
asked by Johann Sebastian Painevil Len 27.12.2018 в 20:56
source

0 answers