I'm with a project using laravel and when I get the controller data, in the view I use a foreach
to recover the data sent, but I would also like each data sent to be stored in an array in Javascript to be able to operate with these.
view:
@foreach($producto as $prod)
<tr>
<td>
<input type="text" min="1" max="100" id="precio" value="{{ $prod->precio }}" readonly="readonly">
</td>
<script>
function calcular(){
var precio = document.getElementById("precio");
var total = precio.value;
var array = [total]
for ( i = 0; i < array.length; i++) {
var resultado = array[i];
console.log(resultado);
}
}
</script>
</tr>
@endforeach
<td>
<button onClick="calcular()" class="btn btn-info" id="calcular">Total</button>
</td>
At the moment of printing the array, it only saves the first data that was in the list when it should show all the data that I sent from the controller.