-2
Personal I have an array with sizes of a product, follow the example of the array:
And for each size I create a button through a foreach, follows excerpt from the code where I create the buttons:
<div class="item item-stock">
<label for="stock">Tamanho: </label>
@foreach($stocks as $stock)
<button id="stock" class="btn-stock" value="{{ $stock->id }}" data-quantity="{{ $stock->quantity }}" onclick="verifyStock();">{{ $stock->unit->name }}</button>
@endforeach
</div>
For me to proceed with my application I need to check if the product has stock and to check this I need the quantity, information that already comes in the array, and I’m trying to play it in a script through an Attributes date, but the problem is that no matter which button I click on it always comes the value of the first element of the array... and as up there I already did a foreach was to be coming right, wasn’t it? Follow below my function js:
$(document).ready(function() {
verifyStock();
});
function verifyStock() {
var quantity = $('#stock').val();
// var quantity = $('#stock').attr('data-quantity');
console.log(quantity);
}
Could someone explain to me what’s missing, where it’s missing and why?