this code is formatting the price like that 500 000 but i need to price format like this 500.000 so i need dot instead space
code at below
code at below
Code:
<html>
<head>
<script type="text/javascript">
window.onload = attachEvents;
function attachEvents() {
document.getElementById('myInput').onkeyup = reformatNumber;
}
function reformatNumber() {
// No error checking. Assumes only ever 1 DP per number
var text = this.value;
// Strip off anything to the right of the DP
var rightOfDp = '';
var dpPos = text.indexOf('.');
if (dpPos != -1) {
rightOfDp = text.substr(dpPos);
text = text.substr(0, dpPos);
}
var leftOfDp = '';
var counter = 0;
// Format the remainder into 3 char blocks, starting from the right
for (var loop=text.length-1; loop>-1; loop--) {
var char = text.charAt(loop);
// Ignore existing spaces
if (char == ' ') continue;
leftOfDp = char + leftOfDp;
counter++;
if (counter % 3 == 0) leftOfDp = ' ' + leftOfDp;
}
// Strip leading space if present
if (leftOfDp.charAt(0) == ' ') leftOfDp = leftOfDp.substr(1);
this.value = leftOfDp + rightOfDp;
}
</script>
</head>
<body>
<form>
<input type="text" id="myInput" />
</form>
</body>
</html>