I have this structure that I generate for each element find by a search
<?php foreach ($this->pneumatici as $pneumatico) :?>
<div class="col-md-3 element-form">
<div class="input-group input-float">
<input type="hidden" name="codice" value="<?= $pneumatico->codice ?>" id="codice">
<input type="text" class="form-control" id="quantita" value="0" size="1" maxlength="2"
<?php if ($pneumatico->quantita == 0){
echo "disabled"
} ?> >
</div>
<?php if ($pneumatico->quantita == 0){
echo '<button class="btn btn-danger btn-disabled" role="button"><strong>ESAURITO</strong></button>';
} else {
echo '<button class="btn btn-primary insert-cart">Aggiungi <span class="glyphicon glyphicon-shopping-cart"></span></button>';
} ?>
<div class="clearfix"></div>
I need when user click on one of the generate button with class='insert-cart'
to put in array these attributes:
-
'#quantita' => val
, '#codice' => val
How I can do?
I tried in this way, but I can get only the first element value and doesn't work for the others
$(".insert-cart").click(function(){
var quantTot = "";
$('#quantita').each(function(){
var quantita = $('#quantita').val();
quantTot += quantita;
if (quantita != 0) {
var id = $('#codice').val();
}
});
});