I have a Form with 3 input
1 Total value
2 parcels
3 Par Value
I need to fill in the total value and the number of parcels, and fill in the parcel value.
Does anyone have a solution in JavaScript or Jquery ??
I have a Form with 3 input
1 Total value
2 parcels
3 Par Value
I need to fill in the total value and the number of parcels, and fill in the parcel value.
Does anyone have a solution in JavaScript or Jquery ??
In this way, when executing an event in the parcel, it already calculates the value per parcel.
<input type="text" placeholder="Valor Total" id="total">
<input type="text" placeholder="Quantidade parcela" id="parcela">
<input type="text" placeholder="Valor por Parcela" id="valorParcela">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
$('#parcela').change(function(){
var valor = parseFloat($('#total').val());
var parcela = parseInt($('#parcela').val());
var totalParcela = valor / parcela;
$('#valorParcela').val(totalParcela);
});
This is simple, just have event headphones that trigger when there are input
in the inputs and convert that input to numbers.
An example would look like this:
var inputs = document.querySelectorAll('input');
var total = inputs[0];
var parcelas = inputs[1];
var valorParcelas = inputs[2];
total.addEventListener('input', calcular);
parcelas.addEventListener('input', calcular);
function calcular() {
valorParcelas.value = Number(total.value || 0) / Number(parcelas.value || 1);
}
label {
display: block;
margin: 5px;
}
<label>Total: <input type="text"/></label>
<label>Parcelas: <input type="text"/></label>
<label>Valor da parcela: <input type="text"/></label>
$('button').click(function(){
var valor = parseFloat($('#total').val())
var parcela = parseInt($('#parcela').val())
var total = valor / parcela
$('#valorParcela').text(total)
})
<input type="text" placeholder="valor Total" id="total">
<input type="text" placeholder="valor Total" id="parcela">
<div id="valorParcela"></div>
<button>Gerar</button>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
Here's an example