Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
147
rated 0 times [  154] [ 7]  / answers: 1 / hits: 15247  / 13 Years ago, mon, september 19, 2011, 12:00:00

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.


More From » javascript

 Answers
17

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 themousedown event instead, or make the button unselectable by adding an unselectable=on attribute.


[#90031] Friday, September 16, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josh

Total Points: 391
Total Questions: 112
Total Answers: 90

Location: Aruba
Member since Fri, Jun 24, 2022
2 Years ago
josh questions
Wed, Aug 4, 21, 00:00, 3 Years ago
Mon, Aug 24, 20, 00:00, 4 Years ago
Wed, Aug 12, 20, 00:00, 4 Years ago
;