View Full Version : Resolved Insert Text into Textare

08-12-2008, 08:31 PM
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.

08-12-2008, 08:43 PM
You've got a missing " ' " infront of your [b**]

Philip M
08-12-2008, 08:44 PM
Is this what you want?

<script type="text/javascript">
function formatText(el,tag){
var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.sel ectionEnd);// IE:Moz
var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
if(document.selection){ //IE
else{ //Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value .length);


<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');" />

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

08-12-2008, 09:09 PM
Thank you so much. You guys are awesome!!