Thread: Resolved Problem with smiley insert
View Single Post
Old 10-04-2012, 02:05 AM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,191
Thanks: 217
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Problem with smiley insert

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


Code:
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();
	}
}

Last edited by durangod; 10-04-2012 at 09:03 AM..
durangod is offline   Reply With Quote