SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting tags into a textarea.

    First, off, I did search google. And I did find something useful, but, knowing nothing to do with JS, I have no clue how to make it come together.

    Here is a code snippet that inserts tags at the cursor position in a textarea.

    http://www.alexking.org/blog/index.php?p=286

    But that is only part of the script. I just need a simple insert -value- into a textarea,

    Thanks!

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the link - I didn't know that was possible. I bet beetle knows more about this

    Here's a simple test I tried on IE6 and Firebird (did not work on Opera7):
    Code:
    <html>
    <head>
    <script>
    // insertAtCursor()
    // found at http://www.alexking.org/blog/index.php?p=286
    function insertAtCursor(myField, myValue)
    {
      //IE support
      if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
      }
      //MOZILLA/NETSCAPE support
      else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)
                      + myValue
                      + myField.value.substring(endPos, myField.value.length);
      } else {
        myField.value += myValue;
      }
    }
    </script>
    </head>
    <body>
    <form onsubmit='return false'>
    <textarea rows='14' cols='30' name='ta'>How to insert at the cursor in a textarea!</textarea>
    <br><input type='button' value='<b>' onclick="insertAtCursor(this.form.ta, '<b>')">
    <input type='button' value='</b>' onclick="insertAtCursor(this.form.ta, '</b>')">
    </form>
    </body>
    </html>

  3. #3
    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)
    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




  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yes

    Excellent work, beetle! You've taken this idea further than the code I posted above

    thanks

  5. #5
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks great

    For that link, do I just copy (most of) the source code, or is there a download option I am somehow missing? Also, won't I need to use PHP (or JS, but i'm a PHP dev...) to turn [url] [etc] into <a href=> etc. ?

  6. #6
    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)
    Well, I don't have any documentation for it, so you'll sorta have to figure-it-out/ask me questions. You will have to look at the source on that link to see how to instantiate the object, but all the hard-working code is here

    www.peterbailey.net/dhtml/js/taeditor.class.js
    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




  7. #7
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh neat, I didn't realize you made that. Thanks!

  8. #8
    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)
    Ya, it's my code, so just PM me or reply to this thread if you have questions.

    If you're converting this to HTML, there are HTML editors out there as well.

    I'm writing one and there's htmlArea 3, which is more complete than mine.
    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





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
  •