Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  13] [ 7]  / answers: 1 / hits: 93317  / 14 Years ago, thu, january 20, 2011, 12:00:00

I am trying to prevent the enter key from being put into a textarea, but it doesn't seem to work.



$('#comment').keyup(function(event) {
if (event.text.charCodeAt() == '10') {
event.preventDefault();
}
});

More From » jquery

 Answers
24

I have written little demonstration on jsfiddle.net, where you can try this code



Everybody has right answer :)



$('#comment').keypress(function (event) {
if (event.keyCode === 10 || event.keyCode === 13) {
event.preventDefault();
}
});

[#94120] Wednesday, January 19, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
samarab

Total Points: 620
Total Questions: 95
Total Answers: 89

Location: Bonaire
Member since Wed, May 11, 2022
2 Years ago
;