Good, I have a code which is giving me a problem.
My code is made up of 3 things, a total variable, another for money received and another to show change or pending payment (depending on the result I received when verifying the total and the money received), for example if my total es = 500, my received = 400 m and another variable must be = Failure to pay: 100.
So far I have a working code but the detail is to show this last variable, it shows me the correct result but I can not make it show if it is change or if it is money pending payment, also the result it gives me is a number Negative whole, I would like it to be shown without the negative if it were a change.
$(document).ready(function() {
var dolar = 17.50;
$('#Total').on('keyup', function() {
var valor = $(this).val();
if (valor == "") {
$('#TotalLbl').text("$00.00");
} else {
$('#TotalLbl').text("Total: $" + parseFloat(valor).toFixed(2));
}
});
$('.money').on('keyup', function() {
var dollar = $('#USD').val() * dolar;
var mx = $('#MXN').val();
valor = parseFloat(mx) + parseFloat(dollar);
if (valor == "") {
$('#Received').text("$00.00");
} else {
$('#Received').text("Received: $" + parseFloat(valor).toFixed(2));
var falta = ($('#Total').val() - valor);
var tot = $('#Total').val();
console.log(falta);
if (parseFloat(falta) < parseFloat(tot))
$('#INeedThisTo0').text("Cambio: $" + parseFloat(falta).toFixed(2));
else
$('#INeedThisTo0').text("Pendiente: $" + parseFloat(falta).toFixed(2));
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input placeholder="Total.." type="number" id="Total" />
<input placeholder="MXN.." type="number" class="money" id="MXN" />
<input placeholder="USD.." type="number" class="money" id="USD" />
<br>
<label id="TotalLbl"></label>
<label id="Received"></label>
<label id="INeedThisTo0"></label>
<label id="Change"></label>