[Javascript] RE: formatting textarea

Jacoby, Peter R. PJACOBY at PARTNERS.ORG
Thu May 2 12:05:48 CDT 2002


Alan,

Here's a page that I put together for a similar project.  It allows the user
to either press the "B" button and enter the text they want to be bold, or
highlight their text and then press the button and it puts the HTML tags
around it (i.e. <b>their text</b>). The "Preview" button displays their
input as HTML and attempts to validate their text as XHTML if they have the
MSXML DLL installed.  

One of the things that I don't like about my solution (and the one that
RichTextBox.com uses) is it uses the old <b> and <i> formatting tags instead
of the CSS style tags.  It would be much better written if it could use
those tags (i.e. <font style="font-weight:bold;">...</font>), but that makes
it much less clear to a novice user, and probably a little harder to
implement.

This code is highly IE specific (I am using IE 5.5) and I have not even
looked into making it portable, but it seems to work well for IE.

Feel free to use the code if you want, and let me know if you have any
questions about it.

http://www.redsoxnews.com/extra/textbox.html

-Peter


> -----Original Message-----
> From:	Alan Easton [SMTP:alan.easton at unn.ac.uk]
> Sent:	Thursday, May 02, 2002 10:11 AM
> To:	'Java-List'
> Subject:	formatting textarea
> 
> Hello People,
>  
> I am wanting users to format text in a textarea clientside before
> submitting it, namely just bold, italics, underline, line and paragraph
> breaks. I don't want them to have to know any html tags to do this.
>  
> Is there a way, using Javascript, they could just highlight the text in
> the textarea they wished formatting, and pressed the appropriate button
> which would insert the tags at the beginning and end of the highlighted
> text.
>  
> Or is there a better alternative to accomplishing this than the way I am
> currently thinking.
>  
> Any help would be appreciated.
>  
> Many Thanks,
>  
> Alan...



More information about the Javascript mailing list