I have the following function which adds commas to the text field. Example: 5000000
is returned as 5,000,000
.
function addComma(values) {
values.value = values.value.replace(",", "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
if (document.getElementById("values"))
payment = parseInt(document.getElementById("values").value);
<label1>Rent</label1> <input id="values" type="text" onkeyup="addComma(this);">
However, I am not able to use it any further with other variables. If i remove parseInt
, it returns NAN
and adding parseInt
returns 5
.
payment = 10;
values = 5,000,000
The following returns PV = payment * NAN5,000,000
while debugging.
PV = payment*values;
What am i doing wrong here? Any help is appreciated. Thank you!