Hi.
I found the following function to retrieve the caret of a textarea:
function doGetCaretPosition (ctrl) {
var CaretPos = 0;
// IE Support
if (document.selection) {
ctrl.focus ();
var Sel = document.selection.createRange ();
Sel.moveStart ('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0')
CaretPos = ctrl.selectionStart;
return (CaretPos);
}
It works fine(althow the textarea needs to be the first visible element after the body), but when i try to retrieve the caret (when its in a new blank line), it doesnt give me the position of the new line, but the end of the previews one.
Example.
This is the text in
my text area.
If i press enter (new line) after area. it will give me the position just after area. and not the new line.
Can you help?
Cheers.
I found the following function to retrieve the caret of a textarea:
function doGetCaretPosition (ctrl) {
var CaretPos = 0;
// IE Support
if (document.selection) {
ctrl.focus ();
var Sel = document.selection.createRange ();
Sel.moveStart ('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0')
CaretPos = ctrl.selectionStart;
return (CaretPos);
}
It works fine(althow the textarea needs to be the first visible element after the body), but when i try to retrieve the caret (when its in a new blank line), it doesnt give me the position of the new line, but the end of the previews one.
Example.
This is the text in
my text area.
If i press enter (new line) after area. it will give me the position just after area. and not the new line.
Can you help?
Cheers.