Also, regarding "The solution seems to be find the exact location of the
selected text.... but how??"
You create a TextRange of the selected text:
var oRng = document.selection.createRange();
/Robert
-----Original Message-----
From: Albetski, Allan [mailto:aalbetski@t...]
Sent: den 15 oktober 2001 17:42
To: javascript
Subject: [javascript] RE: creating a text editor
Try using MSHTML editing. i.e.,
<body>
<div id="TextEditArea" contentEditable="true" style="border=1 solid">
This is the area where the use can edit text
</div>
<p>
<button onClick="toggleBold()">Bold</button>
</body>
<script>
function toggleBold()
{
TextEditArea.focus()
document.focus()
var oSelection = document.selection.createRange()
document.execCommand("Bold")
}
</script>
You can add additional buttons for other operations, Italic, Underline,
etc...
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/ref
erence/methods/execCommand.asp
will get you started. Look for the command identifiers. You may want to post
this to the MSHTML editing forums.
-----Original Message-----
From: vylarus@h... [mailto:vylarus@h...]
Sent: Monday, October 15, 2001 12:26 PM
To: javascript
Subject: [javascript] creating a text editor
I want to a create a simple text editor for my newsletter so that the
other people involved in my website can bold and under line things when
they enter their articles.
the newsletter works with asp where someone enters info in a text box
and then that text is saved in a database. then when we go to mail the
info is put into a HTML/TEXT format email so all <b></b> appear as bold.
what I want to do is let people select some text, click a bold button, and
presto the high lighted word becomes <b>highlighted word</b>. At the
moment this works only if the selected word is unique. I take the
selected word with the var text = document.selection.createRange().text ,
find it in the textarea.value and replace it. But if the word(s) appear
any where before the selected word(s) it will replace the first one it
finds.
The solution seems to be find the exact location of the selected
text.... but how??
You've probable spent many frustrating hours like me... but have you
found any solutions?I can't seem to get my head arounf microsoft's MSDN
help files....
I greatly appreciate your help.