0
Hello,
I’m starting out in web programming, and my question I think is simple, today I have a certain page containing a forech to display of for dynamic a list of an order
<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 am using jquery to update the vlrtotal fields (total value) which would be vlruni multiplication with Qtd, my function;
somar: function () {
$("#vlrTot").val($("#qtd").val()*$("#vlrUni").val());
$("#item_vlrtot[]").val($("#item_qtd").val()*$("#item_vlruni").val());},
Only that as I am using a foreach it is only updating the first field and the rest does not update.
Does anyone have any idea how to make it update all fields regardless of the size of the for?
If you are starting with web, it is suggested not to mix PHP, Javascript and jQuery. It would be good to dominate separately each of the things. And after learning, use jQuery only when really justify. Almost always pure JS solves (and a lot only in PHP already resolves, by the way).
– Bacco
hm, could give a hint of how to solve this issue, maybe using only php. point is I want you to update the field without having to update the page
– Ciro Stodulski de Azevedo
In this case they are 2 separate things. If it is just display, PHP is enough. If the person will change dynamically, and the total follow, it is case for JS. It would be good besides the code posted (which already helps), explain which is the intended result with more details.
– Bacco