Попытка №2
<style>
div.testblock {
width:200px;
margin: 10px;
float: left;
}
div.testblock>textarea {
width:200px;
height: 80px;
clear:booth;
}
</style>
<div class="testblock">
<textarea></textarea>
<div id="panel">
<input type="button" value="A" />
<input type="button" value="B" />
<input type="button" value="C" />
<input type="button" value="D" />
<input type="button" value="E" />
</div>
</div>
<div class="testblock">
<textarea></textarea>
</div>
<div class="testblock">
<textarea></textarea>
</div>
<script>
window.onload = function () {
var inps = document.querySelectorAll("div.testblock"),
len = inps.length;
for (; inps[--len].setAttribute("onclick", "edit(this)"), len;);
}
edit = function (el) {
el.appendChild(panel);
}
panel.onclick = function (e) {
e = e || window.event;
var el = e.target || e.srcElement;
if (el.tagName != "INPUT") return;
var par = this.parentNode || this.parentElement,
tar = par.children[0];
var myValue = el.value,
myValueLen = myValue.length;
if (document.selection) {
tar.focus();
var sel = document.selection.createRange();
sel.text = myValue;
tar.focus();
} else if (tar.selectionStart || tar.selectionStart == '0') {
var startPos = tar.selectionStart,
endPos = tar.selectionEnd,
scrollTop = tar.scrollTop;
tar.value = tar.value.substring(0, startPos) + myValue + tar.value.substring(endPos, tar.value.length);
tar.focus();
tar.selectionStart = startPos + myValueLen;
tar.selectionEnd = startPos + myValueLen;
tar.scrollTop = scrollTop;
} else {
tar.value += myValue;
tar.focus();
}
}
</script>