...

View Full Version : Resolved Problem with smiley insert



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

Philip M
10-04-2012, 07:36 AM
Have you tried asking the author (digioz)?

Note - it is a cursor, not a curser!

durangod
10-04-2012, 07:53 AM
Oops my bad, correction made..

No sir i found that function in a file and was not aware that there was an owner. But i will google his name and ask him for sure.

UPDATE Wow released in 2004 and nothing more, dusty and old for sure..

Philip M
10-04-2012, 08:04 AM
http://www.phorum.org/phorum5/read.php?8,48517

Solution to your problem posted at

http://phpacademy.org/forum/viewtopic.php?t=15893

durangod
10-04-2012, 08:30 AM
Thanks appreciate that

durangod
10-04-2012, 10:36 PM
Just a quick update for those having this issue. I gave up and left it as it was. In that article on the php academy site, the OP displayed his results and his solution and not even that worked, or at least not for me. It kept taking the whole string of page content smiley and all and replacing it on the page instead of just sticking the smiley in there.

And as far as the other examples, i also could not get them to work. Its probably me im not good with js but i wanted to update here in case so you dont get frustrated when it does not work for you either.

So i put it back the way it was and i figure if they want to put a smiley someplace other than the end of the line, they can copy and paste the smiley code where they want in the text... lol

Peace :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum