I have a TextArea, textBox and a button. TextArea has some text e.g This is a cat.
Now my requirement is If someone set cursor position in TextArea and enter text in textbox and click on button the text should be append in cursor position instead of last. e.g.
TextArea: This is a cat.
Cursor position: after “a”
Entered Text in TextBox: black
Output: This is a black cat.
How can I do this using javascript.
Thanks in advance.
I’ve answered this before:
Inserting text at cursor in a textarea, with Javascript
One extra note is that IE will lose the caret position by the time a click event fires on a button. To get round this you can either use the
mousedownevent instead, or make the button unselectable by adding anunselectable="on"attribute.