SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help inserting text into existing innerHTML object??

    I've built a WYSIWYG dhtml editor. Inserting links, images and all that stuff is pretty string forward using execCommand().


    I'm looking for a way where as when a user clicks on a a © button my script will insert a character, such as a copyright symbol, at the current insertion point of an innerHTML object.

    For instance the innerHTML is initally set to :

    foo.innerHTML = 'Wrangler jeans are the best';


    When a user places their cursor after the word Wrangler, then presses the © button, the script would change innerHTML to :


    'Wrangler© jeans are the best';


    Any ideas? I've been looking for a solution for hours.


    Thought: I'm sure there is a javascript function to insert text into a string (innerHTML) at a certain location, however, how do I retrieve the current location of the insertion point?

    Help is greatly appreciated!

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is all your editing done withing a textarea? or ???
    Last edited by beetle; Aug 5, 2002 at 09:00.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is done in Gecko browsers (NS6+, Mozilla, etc) via the selectionStart property of a textarea - it refers to the start of the selection (a caret could be considered a collapsed selection).

    ta.value = ta.value.substring(0, ta.selectionStart) + 'something else' + ta.value.substr(ta.selectionStart);

    Where ta is a reference to the textarea.

    To do this in IE, you have to do something with its TextRange interface... webreference.com has a tutorial on it I think.
    Jason - Contact Me
    Supermoderator @ CodingForums

  4. #4
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Utah
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ?

    I'm still not very clear on how this is done...


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
  •