I have some data that I bring from a foreach and I show them in a table, and each record has a field called quantity, what happens is that this field when I send it through javascript takes the first value from the first record. who follows him, he takes it as if he were the first.
This is the registration list brought by the foreach
:
<?php foreach ($articulos as $articulo): ?>
<tr>
<td><?= $this->Number->format($articulo->idart) ?></td>
<td><?= h($codigo = $articulo->codigo_orion)?></td>
<td><?= h($nombre = $articulo->nombre)?></td>
<?php if($articulo->tipo_item_id == 1){
echo '<td>ELECTRICA</td>';
}elseif($articulo->tipo_item_id == 2){
echo '<td>ELECTRONICA</td>';
}elseif($articulo->tipo_item_id == 3){
echo '<td>FERRETERIA</td>';
}elseif($articulo->tipo_item_id == 4){
echo '<td>INSTRUMENTACIÓN</td>';
}elseif($articulo->tipo_item_id == 5){
echo '<td>COMUN Y REDES</td>';
}elseif($articulo->tipo_item_id == 6){
echo '<td>SALUD Y ALTURAS</td>';
}elseif($articulo->tipo_item_id == 7){
echo '<td>PAPELERÍA</td>';
}else{
echo '<td>PENDIENTE.</td>';
}
?>
<td><?= $this->Number->format($articulo->valor_u)?></td>
<td><?= $this->Html->link(__(''), ['controller'=>'Articulos','action' => 'view', $articulo->idart], array('class' => 'teal-text text-darken-1 fa fa-eye fa-lg')) ?> </td>
<td><input type="text" name="cant[]" class='validate' style='text-align:center' placeholder="Ejemplo: 1" id="cantidad" required/></td>
<td><button class="btn waves-effect waves-light teal fa fa-shopping-cart" refid="<?php echo $articulo->idart; ?>" onClick="getAjax(this)" ></button></td>
</tr>
<?php endforeach; ?>
This is the one I received through javascript
:
<script>
function getAjax(object){
var cantidad = document.getElementById("cantidad").value;
alert(cantidad);
var id = object.getAttribute("refid");
}
</script>
When I run the alert to see what value it sends me it shows me that it only takes the first value, when I send another record it takes the first amount of the first record.