Вся суть в заголовке, bbcode вставляю следующим образом:
this.bbcode = function(id){
var button_id = attribs = id;
button_id = button_id.replace(/\[.*\]/, '');
if(/\[.*\]/.test(attribs)){
attribs = attribs.replace(/.*\[(.*)\]/, '$1');
} else attribs = '';
var start = '['+button_id+attribs+']';
var end = '[/'+button_id+']';
this.insert(start, end);
return false;
}
this.insert = function(start, end){
element = document.getElementById('id_message');
if (document.selection) {
element.focus();
sel = document.selection.createRange();
sel.text = start + sel.text + end;
} else if (element.selectionStart || element.selectionStart == '0') {
element.focus();
var startPos = element.selectionStart;
var endPos = element.selectionEnd;
element.value = element.value.substring(0, startPos) + start + element.value.substring(startPos, endPos) + end + element.value.substring(endPos, element.value.length);
} else {
element.value += start + end;
}
}
После вставки bbcode курсор становится в конец поля.