Well, follow my version of your code(I was just finishing up when @Toby posted the answer)
I believe that the easiest thing would be to use the event onkeyup
to receive the values of inputs
, you can direct the account:
var PV = (PC * CE / 100) + (PC * ST / 100) + (PC * IPI / 100);
(function($) {
$("#precoCompra").maskMoney({thousands:'', decimal:'.', allowZero:true, suffix: ' R$'});
$("#custoempresa").maskMoney({thousands:'', decimal:'.', allowZero:true, suffix: ' R$'});
$("#st").maskMoney({thousands:'', decimal:'.', allowZero:true, suffix: ' R$'});
$("#ipi").maskMoney({thousands:'', decimal:'.', allowZero:true, suffix: ' R$'});
})(jQuery);
function calcular(){
var PC = $("#precoCompra").val().substring(0, $("#precoCompra").val().length-2);
var CE = $("#custoempresa").val().substring(0, $("#custoempresa").val().length-2);
var ST = $("#st").val().substring(0, $("#st").val().length-2);
var IPI = $("#ipi").val().substring(0, $("#ipi").val().length-2);
console.log(PC,CE,ST,IPI);
var PV = (PC * CE / 100) + (PC * ST / 100) + (PC * IPI / 100);
$("#precoVenda").html("R$ "+PV);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://plentz.github.io/jquery-maskmoney/javascripts/jquery.maskMoney.min.js"></script>
Preço de Compra* <br/><input id="precoCompra" class="money" type="text" name="precoCompra" onkeyup="calcular()"/>
<br/>
Custo Empresa* <br/><input id="custoempresa" type="text" name="custoempresa" onkeyup="calcular()"/>
<br/>
Subs. Tributária* <br/><input id="st" type="text" name="st" onkeyup="calcular()"/>
<br/>
IPI* <br/><input id="ipi" type="text" name="ipi" onkeyup="calcular()"/>
<br/>
Preço de Venda: <br/>
<label id="precoVenda" class="money" name="precoVenda"></label>
What should be the calculation formula?
Exp: PC + (CE * 0,2) + ST + (IPI * 0,5)
– MarceloBoni
would be PV = (PC * CE / 100) + (PC * ST / 100) + (PC * IPI / 100)
– opeta
@opeta I did not understand your doubt, be clearer.
– Paulo Roberto