I am trying to build an online calculator and I wanted to format my input into currency while typing.
On this website: https://www.ratehub.ca/cmhc-mortgage-insurance the asking price input box is similar to what I would like to achieve.
I have tried this code here:
$("#formattedNumberField").on('keyup', function(){
var n = parseInt($(this).val().replace(/\D/g,''),10);
$(this).val(n.toLocaleString());
//do something else as per updated question
myFunc(); //call another function too
});
But it would display NaN after typing a number and deleting it, also I can not use the formatted number for future calculation.
Any help would be appreciated!