Html/javascript question?

Andy

New member
I want a button and a textarea. When you click the button it adds the tags <b> and </b> around the text you have highlighted though i want the tags to be invisible but still there. I have this base code:


<script type="text/javascript">
<!--
function formatText (tag) {
var selectedText = document.selection.createRange().text;

if (selectedText != "") {
var newText = "<" + tag + ">" + selectedText + "</" + tag + ">";
document.selection.createRange().text = newText;
}
}
//-->
</script>

<form name="my_form">
<textarea name="my_textarea"></textarea><br />
<input type="button" value="bold" onclick="formatText ('b');" />
<input type="button" value="italic" onclick="formatText ('i');" />
<input type="button" value="underline" onclick="formatText ('u');" />
</form>

I want the tags to be invisible. 10 points for best example!
 
That's actually a bit hard to do, specially to get it working on all browsers. I recomend you that you download the TinyMCE online editor:

http://tinymce.moxiecode.com/
 
Back
Top