i need to put quantity for my products on my database. My products are displayed inside a foreach loop including the textbox for quantity. but only the first textbox is working. Can you please help me? Thanks a lot!
<div class="col-md-9 cartbox">
<?php foreach($result as $row): ?>
<div class="col-md-12 smallbox">
<div class="col-md-3 item_in_box">
<div class="cart_img_div">
<img class="img-responsive prodimage" src="<?php echo $row['prod_image']; ?>">
</div>
</div>
<div class="col-md-3 item_in_box">
<div class="cart_prod_name" data-name="<?php echo $row['prod_name']; ?>">
<?php echo strtoupper($row['prod_name']); ?>
</div>
</div>
<div class="col-md-3 item_in_box">
Quantity: <input type="text" class="cart_txtquantity"/><br>
<input type="button" class="btn btn-warning updateqty" value="Update"/>
</div>
<div class="col-md-3 item_in_box">
<div class="cart_prod_price">
<input type="hidden" class="hidden_price" value="<?php echo $row['price']; ?>"
<b> PHP:</b> <?php echo $row['total_amount']; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<script>
$(document).ready(function () {
$(".updateqty").click(function () {
$.ajax ({
url: "../controller/order/updatequantity.php",
method: "POST",
data: {
prod_name: $(".cart_prod_name").attr('data-name'),
quantity: $(".cart_txtquantity").val(),
price: $(".hidden_price").val()
},
success: function(result) {
alert(result);
},
error: {
function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
}
});
});
});
</script>
$(".hidden_price").val(), so it will find the first, not the one related to your$(".updateqty")