0
I need to take the amount id="valorPorcentagem"
which is the percentage value with the (id="valor_vendedor")
and automatically add to id="comissao"
.
Whereas:
valorPorcentagem / 100 x valor_vendedor = comissao
20 / 100 x 800,00 = 160,00
45 / 100 x 700,00 = 315,00
The total amount of commission = R$ 475,00
html
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<b>Comissão do Vendedor:</b>
<input type="text" name="total" id="comissao" readonly>
<br><br>
<select id="valorPorcentagem">
<option value="20">20</option>
<option value="45">45</option>
</select>
<input id="valor_vendedor" onkeyup="calcular()">
javascript
function calcular() {
var soma = $('.calcular').get().reduce(function(soma, el) {
return (parseFloat(el.value.replace(/\./g, "").replace(",", "."), 10) || 0) + soma;
}, 0);
soma = soma.toFixed(2);
document.getElementById('comissao').value = soma;
mascara(document.getElementById('comissao'), mreais);
}
The HTML (Add Plan) button
<input type="text" name="usuarios[0][comissao_vendedor]" id="valor_vendedor" class="calcular form-control" placeholder="R$" onkeypress="mascara(this,mreais)" onkeyup="calcular()">
$ js
var AddTableRow = function(el) {
var tbody = $(el).closest('table').find('tbody');
var row = tbody.find('tr:last').clone();
var name = row.find('.calcular').attr('name');
var index = parseInt(name.match(/informacao\[(\d+)\]\[porcentagem\]/)[1], 10) + 1;
row.find('[name^="informacao["]').each(function() {
if (this.name) {
this.name = this.name.replace(/^informacao\[\d+\]/, "informacao[" + index + "]");
}
});
tbody.append(row);
};
Where
id=valorPorcentagem
?– MagicHat
It was bad @Magichat forgot.
– Mauro Santos