Well, follow my version of your code ( was just finished when @Toby posted the response rs )
I think the easiest thing to do is to use the onkeyup
event to get the values of inputs
, you can perform the account directly:
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><scriptsrc="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>