<script>function add_commas(number){
//remove any existing commas...
number=number.replace(/,/g, "");
//start putting in new commas...
number = '' + number;
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}
</script>
<input type="text" onkeyup="this.value=add_commas(this.value);" />
http://www.codingforums.com/javascript-programming/228889-add-commas-automatically-when-typing.html