Add tags before and after the highlighted text

Discussion in 'JavaScript' started by red-x, Sep 20, 2008.

  1. #1
    Hi, I'm making my own BBcode and I want to make something that will enter tags like when the user highlights a text they want to add the tags too, like in this forums. I have this script but it enters the tags in front of the text..

    <form method="post" name="addcomment">
    Comment:
    
    <input type="button" onClick="document.addcomment.comment.value+=\'\'" value="Bold" name="bold" title="Add Bold" >
    
    <input type="button" onClick="document.addcomment.comment.value+=\'\'" value="Italic" name="italic" title="Add Italic" >
    
    <input type="button" onClick="document.addcomment.comment.value+=\'[php][/php]\'" value="PHP Code" name="php" title="Add PHP Code" >
    
    <input type="button" onClick="document.addcomment.comment.value+=\'[url=http://linkhere.com]Link text[/url]\'" value="URL" name="url" title="Add Hyperlink" >
    
    <textarea rows="5" cols="35" name="comment"></textarea>
    
    <input type="submit" name="add_comment" value="Submit">
    </form>
    Code (markup):
    Thanks in advance :).
     
    red-x, Sep 20, 2008 IP
  2. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Call a handler script, don't try to do it all with onclick, you'll just make yourself crazy.
     
    Sleeping Troll, Sep 22, 2008 IP