Forum Moderators: open

Message Too Old, No Replies

Can you change font color of text area dynamically?

For chat screen

         

one_mind

10:03 am on Nov 13, 2005 (gmt 0)

10+ Year Member



Hi,

I have a simple chat screen where users enter messages to a mysql table then i want these messages to be displayed in a textarea but have different colored font for each message.
Is there a way to change the font color of a textarea dynamically? I am using php.

Thanks for any help

serverrealty

6:29 pm on Nov 13, 2005 (gmt 0)

10+ Year Member



ofcourse there is.

If you are reading the messages out of the mysql, you have to be reading out code to the browser. So add in the definition to color the text as CSS.

definedcolor1
definedcolor2
definedcolor3
etc

<span class="definedcolor<? echo $loopvariable;?>"><? echo $message;?></span>

make sure you do your change to the loopvariable within each loop though the database to get the differeent definedcolor# styles for each one.

The possibilities are code endless, what I just mention is only way sort of way to complete the task.

Can you code PHP?

one_mind

5:39 am on Nov 14, 2005 (gmt 0)

10+ Year Member



Thanks,

I can use php.

The trouble is, you cant use <span> or any code within the text area as it is just plain text and the code just gets outputed to the textarea. What i need is a rich text area or something. You can only change the overall text color of the text area, not individual elements.

Someone suggested java on another forum but i just need a simple screen for 2 users to message each other and java is a bit overkill. Are there any html and php workarounds?

Thanks again

one_mind

5:45 am on Nov 14, 2005 (gmt 0)

10+ Year Member



Ideally what i need is something that works exactly like a textarea ie. auto scrolling and wrapping ect but the abiltiy to output colored text.

one_mind

5:55 am on Nov 14, 2005 (gmt 0)

10+ Year Member



After reading up on textareas, i have found that it is impossible to format text within a html textarea.
If anyone knows of a script or program thats easy to use and works in most browser please post it :)
I might have to resort to frames :(

Webheavy

8:01 am on Nov 14, 2005 (gmt 0)

10+ Year Member



This works in FF, probably IE:

<textarea style="color: red; font-family: arial;">This is the text in the textarea. Note the color and font.</textarea>

However, I use scrolling DIVs for this job unless you intend to allow the user to edit the textarea. Scrolling DIVs allows formatting within the content but textarea does not.

Does this help?

one_mind

9:01 am on Nov 14, 2005 (gmt 0)

10+ Year Member



Hi Webheavy

The way you done it only changes the over all text style and not individual messages.

I really dont think its possible with textarea and i've never heard of scrolling divs until now and a quick google shows you've found what i'm after :)

Cheers, scrolling divs are exactly what i needed :)

Thankyou!

Webheavy

9:26 am on Nov 14, 2005 (gmt 0)

10+ Year Member



CSS is a real trip. Took me quite awhile to learn it but worth it.

My MySQL app uses scrolling DIVs massively. SQL query results are shown in a scrolling table with dynamically sized and scrolled headers.

I let a TABLE lay out the results grid, then use Javascript with CSS to set the position and widths of the left-right auto scrolling headers. Then more javascript scrolls the headers when the table scrolling DIV is scrolled by the user.
Even more Javascript resizes the scrolling DIV to fill the browser window when the user resizes the window.

Finally, I actually load the content of a scrolling DIV dynamically without reloading the whole page. This is all done with HTML and client side Javascript. It keeps the page as light as possible. Something like 52% use analog modem.

HTH,
Webheavy

serverrealty

2:57 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



not sure if this will help, but what about an iframe for your text?

it will allow you to embedd a "text area" with scrolling, and define text as html.

Good luck again