Percentage javascript or php

Asked

Viewed 188 times

0

I have these three buttons, a cost value - profit margin - sale value. I need him to calculate the automatic sale value, put the cost value put the profit margin it shows within the sales value field automatically, anyone can tell how I can do this?

I tried to do with

function porcentagem_xn ( $porcentagem, $total ) {
    return ( $porcentagem / 100 ) * $total;
}

however I cannot call in the field I want and even if the result automatically appears in the sales value field

<div type="text" class="col-lg-2 ">
    <label >Valor de Custo:</label>
    <input type="int" name="txt_custo" class="form-control number_format">          
</div> 
<div type="text" class="col-lg-1  ">
    <label >Margem(%):</label>
    <input type="int" name="txt_margem" class="form-control"  > 
</div> 
<div type="text" class="col-lg-2  ">
    <label >Valor de Venda:</label>
    <input type="int"  name="txt_venda" class="form-control">           
</div>
  • 1

    The types of inputs may not be the cause of the problem? There is no input type=int but yes input type=number. Other than that, I don’t know what it could be.

2 answers

0

I think this should be used to calculate.

$('.valor').blur(function(){ // uso a classe valor para chamar o blur por mais de um campo
    var custo = $("input[name=txt_custo]").val() || 0;
    var margem = $("input[name=txt_margem]").val() || 0;
    var valor_total = 0;

    valor_total = ( margem / 100 ) * custo ;
    $("#txt_venda").val(parseFloat(valor_total));
});
  • onBlur="$('.value')" that?

0

To calculate the Profit you can do so. In the call of this function pass the value of Cost and the desired profit percentage.

function calculaValor(valorCusto, percentualLucro){
   return (valorCusto + (valorCusto * (percentualLucro / 100)));
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.