2

Possible Duplicate:
How to insert text at the current caret position in a textarea

I want to insert text in a textarea using javascript at the caret position, i already have the code to find the position, whats the code to put text at that particular position?

Thanks,

Jake

Community
  • 1
  • 1
Jake
  • 3,172
  • 6
  • 36
  • 55

1 Answers1

0
var myTextarea = ... // select the text area
$(myTextarea).html('The text I want to insert'); // this will replace the existing contents

To append text to the textarea, use this:

$(myTextarea).html($(myTextarea.html() + 'The text I want to insert');
jtfairbank
  • 2,271
  • 2
  • 19
  • 33