Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  111] [ 3]  / answers: 1 / hits: 27495  / 13 Years ago, fri, april 15, 2011, 12:00:00

I've got the following code:



document.onkeydown=function(e) {
if (e.which == 13 && isCtrl) {
log('Ctrl CR');
} else if (e.which == 17) {
isCtrl = true;
};


I need to insert a Carriage Return/Line feed where the cursor is located in the input textarea.
Now that I think about it, I should probably be using a textarea selector instead of document.onkeydown, but $('textarea').onkeydown doesn't work.


More From » jquery

 Answers
12
$('textarea').keydown(function (e){
var $this = $(this);
if (e.which === 13 && e.ctrlKey) {
$this.val($this.val() + 'rn'); // untested code (to add CRLF)
}
});


Reference




[#92698] Thursday, April 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amari

Total Points: 736
Total Questions: 111
Total Answers: 90

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;