I have the following method where I get a text field from the table.
function save(){
$('#tableDespacho tr').on('click', function(){
//var first = $(this).find('td:first').html();
var area = $(this).find('td:eq(0)').text();
var fecha = $(this).find('td:eq(1)').text();
var cantidad = $(this).find('td:eq(5)').text();
console.log(cantidad);
});
}
I call this method with a button:
<button type="button" onclick="save()" class="btn btn-sm btn-success done" data-toggle="tooltip" data-placement="top" title="Recepcionar Item" data-original-title="Remove item">
<i class='fa fa-check fa-lg '></i>
</button>
Apart I have a button to edit the amount of the table.
$('#tableDespacho').editable({
container: 'body',
selector: 'td.Cantidad',
title: 'Cantidad',
validate: function(value) {
if ($.trim(value) == '') {
return 'Este campo es necesario';
}
var regex = /^[0-9]+$/;
if(! regex.test(value)) {
return 'Solo Numeros!';
}
//if ($(this).text() >= value) {
// return ' Excede cantidad';
//}
}
});
At first it works fine I can edit the quantities and pressing the button shows me the quantity. But then edit and show the amount if I press the table it calls me to the function save
.
Why is this?
table
<table id="tableDespacho" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th class="th-sm">CodPieza</th>
<th class="th-sm">Cantidad</tr>
</thead>
<tbody>
<?php include_once('include/conexion.php');
$sql = "SELECT * FROM Despacho_DetalleEntreAreas ORDER BY Fecha DESC";
$result = mysqli_query($conexion,$sql);
if ($result) {
$resultCheck = mysqli_num_rows($result);
if ($resultCheck >0) {
while ($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td>
<?php echo $row['Desc_Area'] ?>
</td>
<td data-name="Cantidad" class="Cantidad <?php echo $text ?>" data-type="text">
<?php echo $row['Cantidad'] ?>
</td>
<td>
<button type="button" onclick="save()" id="btn" class="btn btn-sm btn-success done" data-toggle="tooltip" data-placement="top" title="Recepcionar Item" data-original-title="Remove item"> <i class='fa fa-check fa-lg mb-1 white-text'></i></button>
</td>
</tr>
<?php } } } ?>
</tbody>
</table>