As already mentioned, make sure you use $ (document) .ready () - http://api.jquery.com/ready/ . In addition, instead of replacing commas with keyup, you should disable them when you press a key, returning false:
$(document.ready(function () { $("input[type=text]").keypress(function (evt) { if (String.fromCharCode(evt.which) == ",") return false; }); });
Example: http://jsfiddle.net/QshDd/
This gives a more professional feeling: "," is blocked without appearing, and then disappears when you release the key. However, like your solution, this will not copy and paste the commas into your input. To do this, you can connect to the onpaste or onchange event.
If you want to use keyup and replace, you really don't need to deal with jQuery wrappers, you can access the value property directly:
$(document.ready(function () { $("input[type=text]").keyup(function (evt) { this.value = this.value.replace(/,/g, ""); }); });
source share