First off, your function can be simplified:
Code:
function doCopyS(smilie) {
document.myform.mytext.value += ' '+smilie;
document.myform.mytext.focus();
}
After getting that, I found this using Google (search terms - move cursor textarea javascript):
Code:
function setCursorPosition(oInput,oStart,oEnd) {
if( oInput.setSelectionRange ) {
oInput.setSelectionRange(oStart,oEnd);
}
else if( oInput.createTextRange ) {
var range = oInput.createTextRange();
range.collapse(true);
range.moveEnd('character',oEnd);
range.moveStart('character',oStart);
range.select();
}
}
at this address:
http://www.faqts.com/knowledge_base/...html/aid/15728
Put it all together:
Code:
function setCursorPosition(oInput,oStart,oEnd) {
if( oInput.setSelectionRange ) {
oInput.setSelectionRange(oStart,oEnd);
}
else if( oInput.createTextRange ) {
var range = oInput.createTextRange();
range.collapse(true);
range.moveEnd('character',oEnd);
range.moveStart('character',oStart);
range.select();
}
}
function doCopyS(smilie) {
document.myform.mytext.value += ' '+smilie;
document.myform.mytext.focus();
setCursorPosition(document.myform.mytext, document.myform.mytext.value.length, document.myform.mytext.value.length);
}
Works here.
Bookmarks