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 4 of 4
  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    Insert Text into Textare

    Ok so I got the BBCode down now I need an input box or image to put on when people make mesages.

    I tried <input type=button value=B name=btnBold onclick=wrapText(document.getElementById('TheTextArea'),[b**]','[/b**]');> but the 's at the end get in the way of the PHP echo. Any ideas?

    I put stars in it to stop from bolding.
    Last edited by UrbanTwitch; 08-12-2008 at 08:09 PM. Reason: insert text into textarea
    Formerly MysticScript

    6+ years club

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    You've got a missing " ' " infront of your [b**]

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Is this what you want?

    Code:
    <script type="text/javascript">
    function formatText(el,tag){
    var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
    var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
    if(document.selection){    //IE
    document.selection.createRange().text=newText;
    }
    else{   //Moz
    el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
    }
    }
    
    </script>
    </head>
    
    <body>
    <form name="myForm">
    <textarea name="myTextarea" rows = "12" cols = "50">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</textarea><br>
    <input type="button" value="Bold" onclick="formatText (myTextarea,'b');" />
    <input type="button" value="Italic" onclick="formatText (myTextarea,'i');" />
    <input type="button" value="Underline" onclick="formatText (myTextarea,'u');" />
    </form>
    I think this script was written by Kor. It works in all browsers.


    "This is the steepest part of the course and I am afraid that it gets steeper later on." - Sports commentator

  • #4
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Thank you so much. You guys are awesome!!
    Formerly MysticScript

    6+ years club


  •  

    Posting Permissions

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