Price: 62,000 Total Payment: 60,000 Amount Missing: 2
And I wanted it to show like this:
Price: 62,000 Total Payment: 60,000 Amount Missing: 2000
<script>
function calcular() {
var num1 = Number(document.getElementById("Preco").value);
var num2 = Number(document.getElementById("TotalPago").value);
var elemResult = document.getElementById("QuantiaFalta")
if (elemResult.textContent === undefined) {
elemResult.textContent = String(num1 - num2);
}
else {
elemResult.innerText = String(num1 - num2);
}
}
</script>
<div class="form-group">
<label class="col-sm-3 control-label">Preço</label>
<div class="col-sm-5">
<input type="text" name="fPreco" id="Preco" class="w3-input w3-animate-input" style="width:135px; border-bottom: 2px solid black" onblur="calcular();" value="<?php echo $Preco; ?>" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Total Pago *</label>
<div class="col-sm-5">
<input type="text" name="fTotalPago" id="TotalPago" class="w3-input w3-animate-input" style="width:350px; border-bottom: 2px solid orange" onblur="calcular();" value="<?php echo $Preco; ?>" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Quantia em Falta *</label>
<div class="col-sm-5">
<span type="text" name="fQuantiaFalta" id="QuantiaFalta" class="w3-input" style="width:350px; border-bottom: 2px solid orange" required></span>
</div>
</div>