Use this, from here:
function insertAtCaret(areaId, text) {_x000D_
var txtarea = document.getElementById(areaId);_x000D_
if (!txtarea) {_x000D_
return;_x000D_
}_x000D_
_x000D_
var scrollPos = txtarea.scrollTop;_x000D_
var strPos = 0;_x000D_
var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?_x000D_
"ff" : (document.selection ? "ie" : false));_x000D_
if (br == "ie") {_x000D_
txtarea.focus();_x000D_
var range = document.selection.createRange();_x000D_
range.moveStart('character', -txtarea.value.length);_x000D_
strPos = range.text.length;_x000D_
} else if (br == "ff") {_x000D_
strPos = txtarea.selectionStart;_x000D_
}_x000D_
_x000D_
var front = (txtarea.value).substring(0, strPos);_x000D_
var back = (txtarea.value).substring(strPos, txtarea.value.length);_x000D_
txtarea.value = front + text + back;_x000D_
strPos = strPos + text.length;_x000D_
if (br == "ie") {_x000D_
txtarea.focus();_x000D_
var ieRange = document.selection.createRange();_x000D_
ieRange.moveStart('character', -txtarea.value.length);_x000D_
ieRange.moveStart('character', strPos);_x000D_
ieRange.moveEnd('character', 0);_x000D_
ieRange.select();_x000D_
} else if (br == "ff") {_x000D_
txtarea.selectionStart = strPos;_x000D_
txtarea.selectionEnd = strPos;_x000D_
txtarea.focus();_x000D_
}_x000D_
_x000D_
txtarea.scrollTop = scrollPos;_x000D_
}
_x000D_
<textarea id="textareaid"></textarea>_x000D_
<a href="#" onclick="insertAtCaret('textareaid', 'text to insert');return false;">Click Here to Insert</a>
_x000D_