Seller javascript commission calculation

Asked

Viewed 99 times

-2

I’m developing a project and I need to calculate the commission. Example: (by typing the total value of the cervix has to give result of service cost in the second input and in the third input the value that the customer will receive, in the code below I was able to calculate the service cost, but I can not calculate the value that the customer will receive,) how could I do this in javascript ?

example [1]: https://i.stack.Imgur.com/Fhhzn.png

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cálculo</title >
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
    <script>
         function calcular() {
        var comissao = (parseFloat($("#valorPorcentagem").val())/100) * parseFloat($("#valor_vendedor").val());
        $("#comissao").val(comissao);
      }
    </script>
   
      <div>
        <h2>Orçamento</h2>
        
      <input value="20"  id="valorPorcentagem" hidden>
      <span>Valor total:</span>
      <input id="valor_vendedor" onkeyup="calcular()">
      <br>
      <br><span>Custo de serviço:</span>
      
      <input type="text" name="custo" id="comissao" readonly>
      <br>
      <br>
        <span>O que voce receberá</span>
      <input type="text" name="pago"  id="sera_pago" readonly>

      
    </div>
</body>
</html>

1 answer

0

function calcular() {
    var comissao = (parseFloat($("#valorPorcentagem").val()) / 100) * parseFloat($("#valor_vendedor").val());
    $("#comissao").val(comissao);
    $("#sera_pago").val($("#valor_vendedor").val() - $("#comissao").val())
}
<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Calculos</title>
      <script src="jquery.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
   </head>
   <body>
      <div>
         <h2>Orçamento</h2>
         <input value="20"  id="valorPorcentagem" hidden>
         <span>Valor total:</span>
         <input id="valor_vendedor" onkeyup="calcular()">
         <br>
         <br><span>Custo de serviço:</span>
         <input type="text" name="custo" id="comissao" readonly>
         <br>
         <br>
         <span>O que voce receberá</span>
         <input type="text" name="pago"  id="sera_pago" readonly>
      </div>
   </body>
</html>

  • What is the need of Listener in the script if you already have one in HTML?

  • Well noted. I made the adjustment. Thank you.

  • Thank you very much Rodrigo, you helped me a lot

Browser other questions tagged

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