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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert into a textarea

    Hi,

    I have this code that lets me insert text into a textarea from a button. Currently, it inserts the text at the end of what is in the textarea. Is there a way to make it insert where the cursor is instead?

    <script>
    function inser1() {
    document.getElementById('ip').value+= '<firstName>'
    }
    </script>

    thanks,

    jo

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Posts
    206
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Not that I know of, without some very complex scripting to guess the character under the cursor...Maybe, however, there is a simpler way.

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,112
    Thanks
    38
    Thanked 498 Times in 492 Posts
    I summitted a solution to another forum recently and it worked for them.

    Try: http://www.webdeveloper.com/forum/s...ad.php?t=110464

    Or look into:
    http://www.sitepoint.com/forums/showthread.php?t=296023
    How can I manipulate the selection and the caret in an input type="text" element in Mozilla browsers and IE/Win?
    http://www.alexking.org/blog/2003/0...ing-javascript/
    http://www.massless.org/mozedit/
    http://parentnode.org/javascript/wo...ursor-position/


  •  

    Posting Permissions

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