My problem is that I am doing a module to capture orders from a restaurant and I use the Typehead plugin to auto-sugest an input. Whatever you choose from the suggestions, I will attach it to a table that I'm creating with JQuery, I'll show you the code:
Creating the table
function agregarOrden(){
var concepto = $('#txtDescripcion').val();
var costo = $('#hdCostoAlimento').val();
var id = $('#hdIdAlimento').val();
$("#tbOrden").append('<tr><td ><input type="hidden" name="id[]" value="'+id+'"/></td><td><input type="text" name="cantidad[]" value="1"/></td><td> '+concepto+'</td><td> '+costo+'</td><td>'+costo+'</td><td> NO</td><td> <a href="#" class="delete">Eliminar</a></td></tr>');
$('.delete').off().click(function(e) {
$(this).parent('td').parent('tr').remove();
});
}
Once you add and edit the table to how the order is going, I have a save button, there I need to obtain the id that I keep in the input that is hidden and the value that the quantity input has to store it later in my table, but I can not do it. Can somebody help me?
$('#btnGuarda').click(function(){
var cad="";
valores=new Array();
var id = 'id';
$("#tbOrden tr").each(function (index) {
$(".idTD").parent("tr").find("td").each(function() {
//if($(this).html() != "coger valores de la fila"){
valores += $(this).text() + " ";
});
});
alert(valores);
/*$('#tbOrden tr').each(function () {
var id= $(this).find('td').eq(0).html();
var cantidad = $(this).find('td').eq(1).html();
valor=new Array(id,cantidad);
valores.push(valor);
});
alert(valores);*/
});
I show you my html:
<div class="container">
<br>
<form class="form" id="frm" method="post">
<input type="hidden" id="hdIdAlimento" name="hdIdAlimento"/>
<input type="hidden" id="hdCostoAlimento" name="hdCostoAlimento"/>
<fieldset>
<div class="card border-primary mb-3" style="max-width: 80rem;">
<div class="card-header"><h4 class="card-title"><p class="text-primary">Toma de ordenes</p></h4></div>
<div class="card-body">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-2" style="color: white;">
<h4>Mesa</h4></div>
<div class="col-sm-4" style="color: white;"><h4>¿Qué deseas ingresar?</h4></div>
<div class="col-sm-1"><span class="badge badge-info" id="spHelp" style="cursor: pointer;">?</span></div>
</div>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-2"><?php getComboMesas();?></div>
<div class="col-sm-6">
<div class="lista-color">
<input type="text" class="form-control" id="txtDescripcion" name="txtDescripcion" style="text-transform: uppercase;"/>
</div>
</div>
<button type="button" name="btnAgregar" id="btnAgregar" class="btn btn-info"><i class="fas fa-check-circle fa-2x"></i></button>
</div>
<br>
</div>
</fieldset>
</form>
<div class="col-lg-16">
<div class="bs-component">
<div class="card border-primary mb-6" style="max-width: 80rem; ">
<div class="card-header"><h5><p class="text-primary">Orden para la mesa:<span id="spMesa"></span></p></h3></div>
<div class="card-body" id="divNewOrden">
<table id="tbOrden" class=" table table-bordered table-striped">
<tr>
<th style="visibility: hidden;">Id</th>
<th>Cantidad</th>
<th>Concepto</th>
<th>Precio</th>
<th>Total</th>
<th>Servido</th>
</tr>
</table>
<br>
<div class="col-sm-10" align="center">
<button id="btnGuarda" name="btnGuarda" class="btn btn-success ">Guardar</button>
</div>
</div>
</div>
</div>
</div>
</div>