Good afternoon guys,
There was a problem, I had a doubt about the sum system with JQUERY, but I would like you to analyze what is wrong with my code because of the error (NaN) with multiple text boxes, what I did is that php generates type a menu only that I can not add the requests independently.
Here's the js riddle: link
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><formaction="#">
<div class="media-body">
<div class="menu-tittle">
</div>
<div class="quantity">
<div class="pizza-add-sub">
<input type="text" id="qtdpedidos" class="qtdpedidos" value="0"/>
</div>
</div>
<div id="item1" class="pizza-price"> <span id="pizza" class="pizza">10.00</span>
</div>
</div>
<div class="quantity">
<div class="pizza-add-sub">
<input type="text" id="qtdpedidos" class="qtdpedidos" value="0"/>
</div>
</div>
<div id="item1" class="pizza-price"> <span id="pizza" class="pizza">10.00</span>
</div>
</div>
<div class="quantity">
<div class="pizza-add-sub">
<input type="text" id="qtdpedidos" class="qtdpedidos" value="0"/>
</div>
</div>
<div id="item1" class="pizza-price"> <span id="pizza" class="pizza">10.00</span>
</div>
</div>
<div class="quantity">
<div class="pizza-add-sub">
<input type="text" id="qtdpedidos" class="qtdpedidos" value="0"/>
</div>
</div>
<div id="item1" class="pizza-price"> <span id="pizza" class="pizza">10.00</span>
</div>
</div>
</form>
<p>Valor do Pedido: R$<span id="resultado" class="resultado">0.00</span></p>
JQUERY
$(document).ready(function() {
$(".pizza-add-sub").append('<div class="plus qty-pizza">+</div><div class="mines qty-pizza">-</div>');
$(".qty-pizza").on("click", function() {
var $button = $(this);
var oldValue = $button.parent().find("input").val();
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
} else {
// Don't allow decrementing below zero
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - 1;
} else {
newVal = 0;
}
}
$button.parent().find("input").val(newVal);
var v1 = $('#item1 span').text();
var v2 = Number(document.getElementById("qtdpedidos").value);
document.getElementById("resultado").innerHTML = parseFloat(v1 * v2).toFixed(2);
});
});