Oto mój kod wstawiający emotikony (na podstawie tego z phpBB):
Kod
function savePos(ObjPos){
if(ObjPos.createTextRange){
ObjPos.textPos = document.selection.createRange().duplicate();
}
}
function add_emot(text){
text = ' ' + text;
if(document.post.tresc.textPos && document.post.tresc.createTextRange){
document.post.tresc.focus();
var textPos = document.post.tresc.textPos;
textPos.text = textPos.text.charAt(textPos.text.length - 1) == ' ' ? text + ' ' : text;
}else{
document.post.tresc.focus();
document.post.tresc.value += text;
}
}
fragment: post.tresc : post to jest nazwa nadana do <form> a tresc to nazwa nadana do <input>
Można to łatwo przerobić do wstawiania tagów.