durangod
10-04-2012, 02:05 AM
Hi, i am having a problem with my smiley insert. It always inserts at the end of the line of text rather than where the cursor is. The smiley needs to be inserted wherever the text cursor is currently located and im not sure how to do that.
Here is the code i have so far. Thanks ;)
function emoticon(id,text) {
var txtarea = document.getElementById(id);
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}
Here is the code i have so far. Thanks ;)
function emoticon(id,text) {
var txtarea = document.getElementById(id);
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}