Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,915
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    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.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,915
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts

    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.

  • Users who have thanked Philip M for this post:

    durangod (10-04-2012)

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    Thanks appreciate that

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •