Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Page and Site Features

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Things To Do With Textarea Form Fields

The primary function of a textarea field is to accept input from a form user for the form processing script to do stuff with. You see their use in feedback forms, for example.

Another Common Use

Another use of the textarea field is to present text, such as program source code, for easy copying. We use this in many of our articles and blog entries. See / for an example. (If no current blog entries contain source code in a textarea field when you arrive, click on the "[MORE ENTRIES]" link at the bottom of the page and then click on likely blog entry titles.)

Automatically Selecting Content

Notice that the content in textarea fields published in the above blog entries is automatically selected when you click it. To make that happen, we use the following attribute in the <textarea...> tag:

onclick="javascript:select()"

Specifying Text Style, Wrap Characteristics, and Read Only

We also use attributes to specify the text style, turn wrap off, and to make the content read only. Here is an example copied from the "Removing Non-Digit Characters" blog entry:

<form>
<textarea 
   cols="44" 
   rows="2" 
   onclick="javascript:select()" 
   style="font-family: monospace; font-size: 12px;" 
   wrap="off" 
   readonly="yes">
$value =~ s/\D//g;
</textarea>
</form>

(The wrap="off" attribute can be important when presenting programming code. Some code, such as JavaScript, is line break sensitive.)

Bold Text and Text/Background Colors

Whether used for accepting user input or for providing text for copying, the textarea field can be formatted in several ways.

To make the text bold, add a "font-weight" definition to the style attribute. To change the text color, add a "color" definition. For background color, add a "background-color" definition.

This make a yellow background for bolded red text, 16 pixels in size:

<form>
<textarea 
   cols="22" 
   rows="5" 
   style="
      font-size:        16px; 
      font-weight:      bold; 
      color:            red; 
      background-color: yellow;" 
    wrap="off">
</textarea>
</form>

Red text on a yellow background is not very attractive for some implementations. Try sky blue on silver. Any web color combinations are available to you.

Textarea Field With Background Image

Background images can be put into textarea form fields.

Here, the image is a photo of the author, placed once (not repeated), and centered in the textarea field. The text is white, 44 pixels in size, and the background is black:

<form>
<textarea 
   cols="15" 
   rows="5" 
   style="
      font-size:           44px; 
      color:               white; 
      background-image:    url(http://flowto.info/will.jpg); 
      background-repeat:   no-repeat;
      background-position: center; 
      background-color:    black;" 
    wrap="off">
</textarea>
</form>

Add a

readonly="yes"

attribute, and nobody can type onto the photo's generous black frame :)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC