SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    Coventry, England
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting text at cursor position in textbox

    Hi,
    This is my first post so apologies if I muck up!

    I am looking to be able to insert some text into a text box on a form without replacing the contents and so that preferably it appears at the cursor position.

    The need is in a content management system, I want to be able to insert the code for an image, from a drop down menu listing the images, into the textbox containing that areas content.

    Any help would be much appreciated thanks
    Ian

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I wouldn't say mucked up...

    Originally posted by realpoint
    Hi,
    This is my first post so apologies if I muck up!
    I'm a little confused about what you want to do here. Is it to limit exactly what you're users input? If that is it, I remember seeing something similar at www.javascriptsource.com/forms...

    Have a look (I'll hunt around now as well)

    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to place the cursor at a certain point, then you'll need to use TextRange or another variant for another browser. Not sure on the code, sorry.

    http://www.google.com/search?q=textrange

  4. #4
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by TechSited
    If you want to place the cursor at a certain point, then you'll need to use TextRange or another variant for another browser. Not sure on the code, sorry.

    http://www.google.com/search?q=textrange
    If it just placing the cursor at a particular place in a form field, just use the JS focus element.
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't that put the cursor at the end of the line, instead of somewhere in the middle of text, for example?

  6. #6
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  7. #7
    SitePoint Zealot easyrew's Avatar
    Join Date
    Nov 2001
    Location
    Milton Keynes, UK
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hmmm...

    I just had a quick go at doing what you want - but no joy I'm afraid.

    This article at MSDN about the TextRange object may help.

    I think the problem is that, although you can retrieve the current position of the cursor in a Textarea (for example), if you then provide a button for the user to click to add some formatting (like the SPF editor), as soon as the user clicks on the button the position in the textarea is lost.

    There must be a way round it - but I don't have time to play further now. If you find a way please let us all know.

    Rich
    If a man stands alone in the forest
    and there's no woman around to hear him,
    is he still wrong?
    w: www.EasyRew.com


Bookmarks

Posting Permissions

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