0
I’m trying to do an ICMS calculation and I’m having an apparently silly problem that is to take the value of inputs from my HTML, I thought the problem was in function, but when I try to give a alert
or console.log()
in the variables, they are "blank" nor a undefined
is returned, which can be?
var vProduto = document.getElementById('vProduto').value;
var frete = document.getElementById('frete').value;
var seguro = document.getElementById('seguro').value;
var dAcessorias = document.getElementById('dAcessorias').value;
var descontos = document.getElementById('descontos').value;
var aliqInter = document.getElementById('aliqInter').value;
var vIPI = document.getElementById('vIPI').value;
var pMVA = document.getElementById('pMVA').value;
var btn = document.getElementById('calcular');
console.log(vProduto);
btn.addEventListener('click', function() {
calculaIcmsST(vProduto, frete, seguro, dAcessorias, descontos, aliqInter, vIPI, pMVA)
alert(vProduto);
});
function calculaIcmsST(vProduto, frete, seguro, dAcessorias, descontos, aliqInter, vIPI, pMVA) {
var baseInter = vProduto + frete + seguro + dAcessorias - descontos;
var vIcmsInter = baseInter * (aliqInter / 100);
var baseST = (vProduto + vIPI + frete + seguro + dAcessorias - descontos) * (1 + (pMVA / 100));
console.log(baseInter, vIcmsInter, baseST)
}
/*8000, 35, 0, 1565, 0, 12, 0, 0*/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<section class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<table class="table table-hover">
<tbody>
<tr>
<td>Aliquota Origem</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="aliqOri">
<span class="input-group-addon">%</span>
</div>
</td>
</tr>
<tr>
<td>Aliquota Destino</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="aliqDest">
<span class="input-group-addon">%</span>
</div>
</td>
</tr>
<tr>
<td>Valor do produto</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="vProduto">
<span class="input-group-addon">R$</span>
</div>
</td>
</tr>
<tr>
<td>Valor dos descontos</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="descontos">
<span class="input-group-addon">R$</span>
</div>
</td>
</tr>
<tr>
<td>Valor do Frete</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="frete">
<span class="input-group-addon">R$</span>
</div>
</td>
</tr>
<tr>
<td>Valor do Seguro</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="seguro">
<span class="input-group-addon">R$</span>
</div>
</td>
</tr>
<tr>
<td>Valor do IPI</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="vIPI">
<span class="input-group-addon">R$</span>
</div>
</td>
</tr>
<tr>
<td>Outras Despesas Acessórias</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="dAcessorias">
<span class="input-group-addon">R$</span>
</div>
</td>
</tr>
<tr>
<td>Aliquota do ICMS Interestadual</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="aliqInter">
<span class="input-group-addon">%</span>
</div>
</td>
</tr>
<tr>
<td>Aliquota do ICMS Intraestadual</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="aliqIntra">
<span class="input-group-addon">%</span>
</div>
</td>
</tr>
<tr>
<td>% do MVA</td>
<td>
<div class="input-group">
<input type="number" class="form-control" aria-label="Amount (to the nearest dollar)" id="pMVA">
<span class="input-group-addon">%</span>
</div>
</td>
</tr>
</tbody>
</table>
<button style="width: 100%" class="btn btn-lg btn-success" id="calcular">Calcular</button>
</div>
</div>
</section>
But it is more difficult for those who are asking because the text editor of the site for whom it is accustomed to use tab and pessimo.
– user83428
to ident the code because when copy and glue it is not identado as I think.
– user83428
our not knew these tricks.
– user83428