I'm retreiving the "In Stock" data using MySQL
<table class="table table-striped table-bordered table-hover results table-fixed">
<thead>
<tr>
<th class="text-center">#</th>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
<th>In Stock</th>
<th style="width: 20%">Quantity</th>
</tr>
<tr class="warning no-result">
<td colspan="8"><i class="fa fa-warning"></i> No Product Found</td>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM products";
$exec = mysqli_query($connection, $query);
while ($row = mysqli_fetch_array($exec)) {
$product_id = $row['product_id'];
$product_name = $row['product_name'];
$description = $row['description'];
$product_quantity = $row['quantity'];
$product_price = $row['sell_price'];
?>
<tr>
<td class="text-center"><?php echo $product_id; ?>
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
</td>
<td><?php echo $product_name; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $product_price; ?></td>
<td><input type="number" value="<?php echo $product_quantity; ?>" id="qtyResult" disabled></td>
<td><input type="number" name="qtyBuy[]" id="qtyBuy" onkeyup="updateStock()"></td>
</tr>
<?php } ?>
</tbody>
</table>
I want to update the In Stock field automatically when I type a number on the quantity field.
The "San Mig Light's" stock is 500 but when I type a number on quantity field, the stock changes to the last record on the table which is 45.
The rest of the row doesn't also work except for the first one.
Here is my jQuery script.
<script>
function updateStock() {
var inputQty = $('#qtyBuy').val();
var inStock = "<?php echo $product_quantity; ?>"
$('#qtyResult').val(inStock - inputQty);
}
</script>