4
Note: Developed with Laravel 5.7.
Note 2: This is the view from "New Request".
The form will dynamically receive the products according to their previously registered items. Until then ok!
The user will mark the product and inform the intended quantity. The problem is the following:
Multiply unit value by quantity and sum results!
<div class="form-check">
@php
$p = count($produtos);
$i = 0;
@endphp
@foreach ($produtos as $produto)
@php
$i++;
@endphp
<div class="row ">
<div class="col-8 produto">
<input class="form-check-input" type="checkbox" id="produto_id[{{ $i }}]" value="{{ $produto->id }}" name="produto_id[{{ $i }}]" >
<label class="form-check-label" for="inlineCheckbox1" style="margin-right: 10px">{{ $produto->nome }} - R$ {{ $produto->valor }}</label>
<div class="valor">
<input type="hidden" name="val_un[{{ $i }}]" value="{{ $produto->valor }}" id="val_un[{{ $i }}]">
</div>
</div>
<div class="col fields">
<input class="form-control" type="text" id="quantidade[{{ $i }}]" name="quantidade[{{ $i }}]" onblur="sum()" placeholder="Quantidade" >
</div>
</div>
<hr>
@endforeach
<script type="text/javascript">
function sum()
{
let total = 0;
let valor = 0;
let valor_un = 0;
$('.fields input').each(function() {
valor = $('.fields input').val();
valor_un = $('.valor input').val();
total_un = valor*valor_un;
total = ????????????????????????????????????
});
$('#total').val(total);
}
</script>
</div>
<div class="row">
<div class="col-8">
<div class="form-group">
<label for="total">Valor Total</label>
<input type="total" class="form-control" id="total" name="total" aria-describedby="emailHelp" value="">
</div>
</div>
What is the format of the values in
value="{{ $produto->valor }}"
? Seria10,00
(a comma in cents), or10.00
(penny stitch)?– Sam
Good afternoon @Sam, the value comes already with point. Ex: 12.10
– Denis Vanoni
Then I’ll have to change the answer. Just a moment.
– Sam
So @Sam, the value returned in total is Nan.. I haven’t figured out the problem yet!! kk
– Denis Vanoni
I already changed the answer.
– Sam
Dear @Sam, I’ll send you the code again to see what’s going on!
– Denis Vanoni
Let’s go continue this discussion in chat.
– Sam