Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-04-2012, 02:05 AM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
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
Old 10-04-2012, 07:36 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Have you tried asking the author (digioz)?

Note - it is a cursor, not a curser!
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 10-04-2012, 07:53 AM   PM User | #3
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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..

Last edited by durangod; 10-04-2012 at 07:57 AM..
durangod is offline   Reply With Quote
Old 10-04-2012, 08:04 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
http://www.phorum.org/phorum5/read.php?8,48517

Solution to your problem posted at

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

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
durangod (10-04-2012)
Old 10-04-2012, 08:30 AM   PM User | #5
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Thanks appreciate that
durangod is offline   Reply With Quote
Old 10-04-2012, 10:36 PM   PM User | #6
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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
durangod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:56 PM.


Advertisement
Log in to turn off these ads.