Hi,
I have a textarea and I'd like to input some tags around a selection that the user makes... Like adding <B> and </B> around it, so it can later be used on a webpage...
I can get it at the end of the textarea but I'd like it to be around the selected text
Here's what I've got so far:
I have no clue how I have to get it around the selected area, now the selected area gets copied at the end of the textarea
Thanx in advance,
math
I have a textarea and I'd like to input some tags around a selection that the user makes... Like adding <B> and </B> around it, so it can later be used on a webpage...
I can get it at the end of the textarea but I'd like it to be around the selected text
Here's what I've got so far:
Code:
<HTML>
<HEAD>
<script language="JavaScript">
<!-- Hide
function end(){
document.editor.area.value = document.editor.area.value + "\n</body>\n</html>\n";
}
function preview(){
temp = document.editor.area.value;
preWindow= open("", "preWindow","status=no,toolbar=no,menubar=yes");
preWindow.document.open();
preWindow.document.write(temp);
preWindow.document.close();
}
function bold() {
text = (document.all) ? document.selection.createRange().text : document.getSelection();
document.editor.area.value = document.editor.area.value + "<b>"+text+"</b>";
}
// --> De-Hide
</script>
</HEAD>
<BODY>
<form name="editor">
<center>
<textarea name="area" rows=12 cols=50 wrap=physical>
</textarea>
<p>
<table border=0>
<tr>
<td valign=top>
<input type="button" value=" Bold " onClick="bold()">
<input type="button" value=" Italics " onClick="italic()">
<input type="button" value=" Underline " onClick="underline()"><br>
<input type="button" value=" Line Break " onClick="lbreak()">
<input type="button" value=" Paragraph Break" onClick="pbreak()">
</td>
</tr>
</table>
</center>
<p>
</form>
</BODY>
</HTML>
I have no clue how I have to get it around the selected area, now the selected area gets copied at the end of the textarea
Thanx in advance,
math