Forum Moderators: open

Message Too Old, No Replies

How to format the text inside of textarea box?

         

phphelp

4:55 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



Hi everybody,

I am trying to display some info from my database into a textarea box. I just find out it's hard to format the text after I do that. Is anybody know is there anyway to do this?

tedster

8:45 pm on Apr 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello phphelp, and welcome to the forums.

You can define a class in your css stylesheet, and then apply that class to the textarea elements where you want to control the formatting in that particular way.

CSS

.myformat {
font-family:Verdana,Arial,Helvetica,san-serif;
font-size:14px;
color:#fff;
background-color:#000;
}

<textarea class="myformat">Generated content</textarea>

phphelp

9:08 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



Hi tedster,

Thanks for your suggestion, however, what if I need the following:
[textarea]
Welcome to blablabla,
You may find the following info at this location
[/textarea]

where "Welcome to blablabla" is displayed as bold text?

Thanks

phphelp

colorspots

9:57 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



font-weight: bold;

tedster

10:37 pm on Apr 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As far as I know there is no general way to apply different formatting to different parts of the same textarea. However, since you just want to format the first line differently, you might use the pseudo-element :firstline and take care that the bold words will acually fit on the first line. Then a simple line break (not a <br> tag) in your text will begin the second line.

This example works in IE6, but not in FireFox or Opera.

<html>
<head>
<style type="text/css">
textarea.special {
font-family:arial;
font-size:14px;
}
textarea.special:first-line {
font-weight: bold;
}
</style>
</head>
<body>

<textarea class="special" rows="3" cols="50">
Welcome to blablabla,
You may find the following info at this location
</textarea>
</body>
</html>

phphelp

12:33 am on Apr 19, 2005 (gmt 0)

10+ Year Member



Thanks guys, it works fine now.

phphelp

kaled

9:00 am on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code works in IE but not Firefox.

I am very surprised that it works at all. I would expect <TEXTAREA> to be implemented with a simple edit control. In order for formatting to be applied, it must be implemented as a Windows RichEdit control.

Kaled.