Javascript Number Formatting With Commas
I improvised the answer in the comment. What you would need is the below code only. Check this out and also the fiddle:
$(document).on('keyup', '.test', function() {
var x = $(this).val();
$(this).val(x.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
});
Fiddle: http://jsfiddle.net/praveenscience/R8JrF/1/
The reason why it didn't work was, once you make changes, you need to remove all the commas, and do the formatting again, which was not done in the OP's code as well as the other answer code.
Use Number.prototype.toLocaleString();
check here
var no = 3456;
no.toLocaleString();
Gives 3,456