Reputation: 3697
I have the code:
$("#txtDescription").blur(function(){
$("#txtDescription").text($("#txtDescription").text().replace('@', ''));
})
which removes the @ symbol is someone copies it into a text area. The problem with this is that in IE (all versions) it also removes any line breaks which were added and adds all text on a single line with spaces. The other problem is that if I save the information to a DB table the line breaks are actually there so it only seems to be a visual thing. Not good if a user thinks their information is all on a single line.
Does anyone have any suggestions how to remove characters if a user pastes into a textarea?
Upvotes: 2
Views: 323
Reputation: 3088
$("#txtDescription").blur(function(){
var newval = $(this).val().replace('@','');
$(this).val(newval);
})
Upvotes: 1
Reputation: 65264
$("#txtDescription").blur(function(){
$(this).val(function(i,val){
return val.replace('@', '')
});
});
Upvotes: 1
Reputation: 29091
if #txtDescription
is a <textarea>
as your post suggests, then you want to use jQuery's val
function instead of text
.
Upvotes: 2