Hello,
I'm starting in web programming, and my question I believe is simple, Today I have a certain page that contains a forech to display a list of a request for dynamically
<tbody>
<?php $i =0; foreach($itens as $item): ?>
<tr>
<td>
<?= $item->item_id ?>
</td>
<td>
<?= $item->getNomeProduto($item->item_prod) ?>
</td>
<td>
<?php if($pedMagazine->maga_tolerancia==1){?>
<input type="number" name="item_vlruni" id="item_vlruni" value="<?= $item->item_vlruni?>" disabled/>
<input type="hidden" name="item_vlruni[]" value="<?= $item->item_vlruni?>" />
<?php }else echo $item->item_vlruni ;?>
</td>
<td>
<?php if($pedMagazine->maga_tolerancia==1){?>
<input type="number" name="item_qtd" id="item_qtd" min="<?= round($item->item_qtd*(1-($pedMagazine->maga_toleranciaperc/100)))?>" max="<?= round($item->item_qtd*(1+($pedMagazine->maga_toleranciaperc/100)))?>" onchange='sePedidoItem.somar();' step="1"
value="<?= $item->item_qtd?>" />
<input type="hidden" name="item_id[]" value="<?= $item->item_id?>" />
<?php }else {echo $item->item_qtd; }?>
</td>
<td>
<?php if($pedMagazine->maga_tolerancia==1){?>
<input type="number" name="item_vlrtot[]" id="item_vlrtot" value="<?= $item->item_vlrtot?>" disabled/>
<input type="hidden" name="item_vlrtot[]" value="<?= $item->item_vlrtot?>" />
<?php }else echo $item->item_vlrtot; ?>
</td>
<?php //$subTotal+=$item->item_vlrtot ;?>
</tr>
<?php $i++; endforeach; ?>
</tbody>
I'm using jquery to update the fields of vlrtotal (total value) that would be multiplying vlruni with qtd, my function;
somar: function () {
$("#vlrTot").val($("#qtd").val()*$("#vlrUni").val());
$("#item_vlrtot[]").val($("#item_qtd").val()*$("#item_vlruni").val());},
But since I'm using a foreach it is only updating the first field and the rest does not update.
Does anyone have any idea how to do it to update all fields regardless of the size of the for?