0
- I have a problem that I can not solve, Function calculate() subtracts the price by the total paid and shows in the amount, only when showing in quantiafalta, it shows so:
Price: 62.000 Total Paid: 60.000 Outstanding amount: 2
And I wanted him to show it like this:
Price: 62.000 Total Paid: 60.000 Missing Amount: 2,000
<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>
When you are creating the question, you are asked to do a search here in the community to see if this problem has not been solved and so send duplicate content. What have you researched? I also invite you to do the [tour] to learn the basics of how the site works.
– Woss
62,000 is 62,000 or 62 with 3 decimal places? The problem is that at this point if it is written 62,000 parseint returns 62
– Isac
Possible duplicate of How to represent money in Javascript?
– Woss
a simple way and set input inputs as 62000.00 and 60000.00
– user60252