Multiply product price by quantity

Asked

Viewed 52 times

0

Good morning. I am a beginner programmer and I am developing a sales app, where the system includes the products dynamically in the sale. The products are already registered in the database, and wanted to enter the amount of products that will be sold, it already multiply by the price.

Code:

function somaTotal() {
    var total = 0;

    $(".input_preco_venda").each(function() {
        total += parseFloat($(this).text());
    });

    $(".soma_venda").text(total);

    $("[name=soma_venda]").val(total);
}

$(document).ready(function () {
    $(document).on("keyup", ".input_quantidade_venda", function() {
        var indice = $(".input_quantidade_venda").index(this);
        var n1 = parseInt(this.value, 10);
        
        // Esse "10" é o que deveria ser o preço do produto
        $('.input_preco_venda:eq('+indice+')').html(n1 * 10);
        somaTotal();
    });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<table>
  <tr class="row">
    <td>
      <div class="input-field col s6">
        <input placeholder="Digite o Produto" name="input_produto_venda[]" id="produto_venda" type="text" class="validate autocomplete_produto_venda">
        <div id="caixa_auto_complete_produto_venda"></div>
        <label class="active" for="input_produto_venda[]">Produto</label>
      </div>
      <div class="input-field col s2">
        <input placeholder=" " name="input_quantidade_venda[]" class="input_quantidade_venda" type="text" class="validate" value="1">
        <label class="active" for="input_quantidade_venda[]">Quantidade</label>
      </div>
      <div class="input-field col s2">
        <div class="input_preco_venda"></div>
          <label class="active" for="input_preco_venda">Preço</label>
        </div>
        <div class="input-field col s4">
      </div>
    </td>
  </tr>
</table>

  • 1

    You want me to pull from the bank the value in real time?

  • Exactly @Sam

  • Then you have to use Ajax. There is mt thing here on the site in relation to this.

No answers

Browser other questions tagged

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