0
Good afternoon.
I need to do a calculation without refresh, but I’m encountering difficulties. I’ll try to explain this in the image below:
<script type="text/javascript">
var xazul = 0;
function buttonazul1() {
document.getElementById('output-azul').innerHTML = ++xazul;
}
function buttonazul2() {
document.getElementById('output-azul').innerHTML = --xazul;
}
</script>
<table style="margin: 0 auto;">
<tr>
<td>
<button type="submit" class="btn btn-default" onclick="buttonazul2()">
<i class="fa fa-minus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
<td>
<span id="output-azul">0</span>
</td>
<td>
<button type="submit" class="btn btn-default" onclick="buttonazul1()">
<i class="fa fa-plus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
</tr>
</table>
I programmed the button to add +1 to SPAN, so that the customer chooses the quantity of each product. I need to take that value, multiply it with the unit value of the product, which I’m going to leave in a field hidden
, show subtotal and then add the entire subtotal column to give the final purchase total.
Anyway, is this the best method? Is there a better method? How could I perform these calculations, just by clicking the 'more' and 'less' button'?
I replicated your code and it did not reproduce errors...
– Felipe Avelar
Oops! The '+' and '-' part works normal. I just wanted to understand the logic to make this account.
– Hebert Richard Masseno Dias
I’m trying to do the operation I described in the image, only I couldn’t create the logic to perform all these calculations without refresh.
– Hebert Richard Masseno Dias
@Cyberplague, my instruction was not to repurpose the question. It is to create a new question, it was good this way, the code, preferably, should be placed directly in the question users prefer so. And in the new question remove the refresh part that has already been solved.
– Augusto Vasques
https://answall.com/questions/413058/somar-subtrair-extrair-subtotal-e-total-final-com-javascript-jquery
– Hebert Richard Masseno Dias
@Cyberplague, the question was very good. I left the +1. I saw that you already had an answer if she solved your problem consider accepting it. If you have questions about how to accept a reply read How and why to accept an answer
– Augusto Vasques