I have a pertinent question about updating dynamically:
I have a ordering system.
The problem is that the values are not being summed correctly in the click event.
InthefirstimageIjustclickthe"+" button and the text box adds the number.
In the second the value of the request receives all the value already added.
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="media-body">
<div class="menu-tittle">
</div>
<div class="quantity">
<form action="#">
<div class="pizza-add-sub">
<input type="text" class="qtdpedidos" />
</div>
</form>
</div>
<div class="pizza-price"> <span class="pizza">10.00</span>
</div>
</div>
<p>Valor do Pedido: R$<span class="resultado">0.00</span></p>
JS
$(".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 total = 0;
var valorPizza = $('.pizza').text().substring(0, $('.pizza').text().indexOf('.'));