Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: RE: creating a text editor


Message #1 by "Mark McKinney" <mmckinney@f...> on Thu, 25 Apr 2002 19:50:20
This a good solution.  There is one problem though, that I have not found 
a solution for.  When you have other controls on the page, the 
TextEditArea loses focus.  If you then click your button, it will give 
back focus to the TextEditArea, but the TextRange now defaults to the 
first position of the control and nothing happens.  You can't even warn 
the user when the focus moves before they click the button, that they need 
to have the focus on the TextEditArea before hitting the button.  Any 
solution for this problem???

TIA,
Mark

> 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.
> ---

  Return to Index