I need help to create a condition to calculate the quantity of the product

Asked

Viewed 37 times

0

The code below is with the function of adding the item by checkbox, need help so that it was by quantity, in the case of input in which the user will insert the quantity and calculate according to the quantity given.

CODIGO JS

var pedido = "" 
const pedidosDisponiveis = document.querySelectorAll("input[type=checkbox]")
var pedidoSelecionado = ""
var soma = 0; 
for ( pedido of pedidosDisponiveis) {
    var pedidoSelecionados = pedido.checked
    
    if(pedido.checked == true) {
        pedidoSelecionado +=` ${pedido.id} -> ${pedido.value} Reais; ` 
        var pedidosValores  =  parseInt(pedido.value)
        soma += pedidosValores   
    }
}

HTML CODE

<div class="item-txt">
    <strong>Pizza</strong>
    <span class="item-sub-txt"> Molho, mussarela, calabresa, cebola fatiada e orégano</span>
</div>

<div class="item-numeros-container">
    <div class="item_valor">
        <div>R$ 7,00</div>
    </div>

    <div class="item_quant">

        <div>
            <input type="checkbox" value=7,00 name="item-checkbox" class="item-checkbox"
                id="Pizza">
        </div>
        
    </div>
</div>

1 answer

0

Good morning!

You can replace this checkbox input with an input of type number, where in it you could set the maximum and minimum value and it would only allow entry of numbers.

HTML code

      <div>
        <label for="quantidade">Quantidade:</label>
          <input type="number" id=quantidade min="1" max="10">
      </div>

Browser other questions tagged

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