devxlogo

Inserting Text at Cursor Position

Inserting Text at Cursor Position

Question:
How can I insert text in a textarea at the current cursor position ? I am able to insert it at the end, for example: textarea.value = textarea.value + “blah blah”. But I would like to insert it at the current cursor position.

Answer:
Unfortunately, the functionality you describe is all you have to work with. You can add text before or after the current contents of the TEXTAREA element, but because there is no way to determine the current cursor position within the control you can’t add text at the user’s current cursor position.

devx-admin

Share the Post: