1
How to subtract the value of the "subtotal" field and how to sum all "subtotals" to generate the final total of this code?
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8" style="border:solid 1px #ffffff; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; padding:1%;">
<!-- SELA BROCA AZUL -->
<div class="input-group mx-auto text-center justify-content-center align-self-center">
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<label>Kit Sela Broca<SUP>®</SUP> Azul</label>
</div>
<div class="col-md-4 mx-auto justify-content-center align-self-center">
<script type="text/javascript">
var xAzul = 0;
var xRosa = 0;
var xVerde = 0;
var xTransparente = 0;
var xColorido = 0;
var Valor = 150;
function adicionarAzul() {
document.getElementById('quantidadeAzul').innerHTML = ++xAzul;
document.getElementById('SubTotalAzul').innerHTML = document.getElementById('quantidadeAzul').innerHTML * Valor;
}
function adicionarRosa() {
document.getElementById('quantidadeRosa').innerHTML = ++xRosa;
document.getElementById('SubTotalRosa').innerHTML = document.getElementById('quantidadeRosa').innerHTML * Valor;
}
function adicionarVerde() {
document.getElementById('quantidadeVerde').innerHTML = ++xVerde;
document.getElementById('SubTotalVerde').innerHTML = document.getElementById('quantidadeVerde').innerHTML * Valor;
}
function adicionarTransparente() {
document.getElementById('quantidadeTransparente').innerHTML = ++xTransparente;
document.getElementById('SubTotalTransparente').innerHTML = document.getElementById('quantidadeTransparente').innerHTML * Valor;
}
function adicionarColorido() {
document.getElementById('quantidadeColorido').innerHTML = ++xVerde;
document.getElementById('SubTotalColorido').innerHTML = document.getElementById('quantidadeColorido').innerHTML * Valor;
}
function subtrairAzul() {
document.getElementById('quantidadeAzul').innerHTML = --xAzul;
}
function subtrairRosa() {
document.getElementById('quantidadeRosa').innerHTML = --xRosa;
}
function subtrairVerde() {
document.getElementById('quantidadeVerde').innerHTML = --xVerde;
}
function subtrairTransparente() {
document.getElementById('quantidadeTransparente').innerHTML = --xTransparente;
}
function subtrairColorido() {
document.getElementById('quantidadeColorido').innerHTML = --xVerde;
}
</script>
<form>
<table style="margin: 0 auto;">
<tr>
<td>
<button type="button" class="btn btn-default" onclick="subtrairAzul()">
<i class="fa fa-minus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
<td>
<span id="quantidadeAzul">0</span>
</td>
<td>
<button type="button" class="btn btn-default" onclick="adicionarAzul()">
<i class="fa fa-plus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
</tr>
</table>
</form>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<div id="SubTotalAzul"></div>
</div>
</div>
<!-- SELA BROCA AZUL -->
<!-- --------------- -->
<!-- SELA BROCA ROSA -->
<div class="input-group">
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<label>Kit Sela Broca<SUP>®</SUP> Rosa</label>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<form>
<table style="margin: 0 auto;">
<tr>
<td>
<button type="button" class="btn btn-default" onclick="subtrairRosa()">
<i class="fa fa-minus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
<td>
<span id="quantidadeRosa">0</span>
</td>
<td>
<button type="button" class="btn btn-default" onclick="adicionarRosa()">
<i class="fa fa-plus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
</tr>
</table>
</form>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<div id="SubTotalRosa"></div>
</div>
</div>
<!-- SELA BROCA ROSA -->
<!-- --------------- -->
<!-- SELA BROCA VERDE -->
<div class="input-group">
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<label>Kit Sela Broca<SUP>®</SUP> Verde</label>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<form>
<table style="margin: 0 auto;">
<tr>
<td>
<button type="button" class="btn btn-default" onclick="subtrairVerde()">
<i class="fa fa-minus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
<td>
<span id="quantidadeVerde">0</span>
</td>
<td>
<button type="button" class="btn btn-default" onclick="adicionarVerde()">
<i class="fa fa-plus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
</tr>
</table>
</form>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<div id="SubTotalVerde"></div>
</div>
</div>
<!-- SELA BROCA VERDE -->
<!-- --------------- -->
<!-- SELA BROCA TRANSPARENTE -->
<div class="input-group">
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<label>Kit Sela Broca<SUP>®</SUP> Transparente</label>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<table style="margin: 0 auto;">
<tr>
<td>
<button type="button" class="btn btn-default" onclick="subtrairTransparente()">
<i class="fa fa-minus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
<td>
<span id="quantidadeTransparente">0</span>
</td>
<td>
<button type="button" class="btn btn-default" onclick="adicionarTransparente()">
<i class="fa fa-plus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
</tr>
</table>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<div id="SubTotalTransparente"></div>
</div>
</div>
<!-- SELA BROCA TRANSPARENTE -->
<!-- --------------- -->
<!-- SELA BROCA COLORIDO -->
<div class="input-group">
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<label>Kit Sela Broca<SUP>®</SUP> Colorido</label>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<table style="margin: 0 auto;">
<tr>
<td>
<button type="button" class="btn btn-default" onclick="subtrairColorido()">
<i class="fa fa-minus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
<td>
<span id="quantidadeColorido">0</span>
</td>
<td>
<button type="button" class="btn btn-default" onclick="adicionarColorido()">
<i class="fa fa-plus-circle fa-2x" style="color:#FFFFFF;"></i>
</button>
</td>
</tr>
</table>
</div>
<div class="col-md-4 mx-auto text-center justify-content-center align-self-center">
<div id="SubTotalColorido"></div>
</div>
</div>
<!-- SELA BROCA COLORIDO -->
</div>
<div class="col-md-2"></div>
</div> <!-- ROW -->
<!-- Espaço -->
<!-- ------ -->
<div class="container-fluid">
<div class="row">
<div class="col-md-12 space">
</div>
</div>
</div>
<!-- ------ -->
<!-- Espaço -->
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<h4 style="text-align: center;">Valor total: <span id="totalGeral" class="totalGeral"></span></h4>
</div>
<div class="col-md-4"></div>
</div>
Thank you!
Taffarel, almost perfect! The behavior of the "-" button is not correct. By clicking this button, in addition to assigning a negative value to the fields, it does not subtract correctly. But we are close! Thanks for your time!
– Hebert Richard Masseno Dias
When you have a little time, I’ll correct it. Thank you.
– Taffarel Xavier