0
I am having trouble updating the net value field of my page. I have the following fields in my HTML:
<input type="number" id="total" value="<?=$faturamento['valor_total'];?>" readonly name="valor" class="form-control">
<input type="number" class="form-control" id="frete" onchange="atualizaTotalLiquido()">
<input type="number" class="form-control" id="desconto" onchange="atualizaTotalLiquido()">
<input type="text" class="form-control" id="valor_liquido" value="<?=$faturamento['valor_total'];?>">
And this is my jquery;
function atualizaTotalLiquido(){
var frete = $("#frete").val();
var desconto = $("#desconto").val();
var total = $("#total").val();
var valor_liquido = $("#valor_liquido");
var total_liquido = total+frete-desconto;
valor_liquido.text(total_liquido);
}
But the total liquid field does not change.
Solution:
$(document).ready(function () {
$('#frete').change(function(){
atualizaTotalLiquido();
});
$('#desconto').change(function(){
atualizaTotalLiquido();
});
function atualizaTotalLiquido(){
var valor_liquido = 0;
//var total_liquido = total+frete-desconto;
valor_liquido = Number($("#total").val()) + Number($("#frete").val()) - Number($("#desconto").val());
$('#valor_liquido').val(valor_liquido).toFixed(2);
}
});
Change
.text
for.val
.– Sam
Even so it doesn’t work. And I tried to log the fields I search and the values come, but it doesn’t work.
– Bruno
It did work. I will edit my question with the solution.
– Bruno