textarea focus point
I was wondering if there is a way to to detect where the cursor is currently focused in a textarea.
I'm currently using this method to add HTML line breaks:
document.forms.elements.value = document.forms.elements.value + '<br>';
But this will obviously just add the BR tags at the end of the text. Thanks in advance.
Gecko-based browsers have a:
property of text inputs and textareas. They refer to the selection range in the box. If the selection is collapsed (i.e. a caret is blinking), both values are equal to each other and refer to the position of the caret in the text.
It is much more complicated in IE revolving around some use of the nasty TextRange interface, a quick search of MSDN though for document.selection should answer your question for IE browsers.