I have a form where I have a couple hundred text boxes and I’d like to remove any commas when they are loaded and prevent commas from being entered. Shouldn’t the follow code work assuming the selector is correct?
$(document).ready(function () {
$("input[id*=_tb]")
.each(function () {
this.value.replace(",", "")
})
.onkeyup(function () {
this.value.replace(",", "")
})
});
See here for an explanation and examples of the javascript
string.replace()function:http://davidwalsh.name/javascript-replace
as @Vega said, this doesn’t write the new value back to the textbox – I updated the code to do so.