home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeHTML & XHTML: The Definitive GuideSearch this book

9.7. Multiline Text Areas

The conventional and hidden-text types for forms restrict user input to a single line of characters. The <textarea> form tag sets users free.

9.7.1. The <textarea> Tag

As part of a form, the <textarea> tag creates a multiline text entry area in the user's browser display. In it, the user may type a nearly unlimited number of lines of text. Upon submission of the form, the browser collects all the lines of text, each separated by "%0D%0A" (carriage return/line feed), and sends them to the server as the value of this form element, using the name specified by the required name attribute.

<textarea>

Function:

Create a multiline text input area

Attributes:

ACCESSKEY

ONKEYPRESS

CLASS

ONKEYUP

COLS

ONMOUSEDOWN

DIR

ONMOUSEMOVE

DISABLED

ONMOUSEOUT

ID

ONMOUSEOVER

LANG

ONMOUSEUP

NAME

ONSELECT

ONBLUR

READONLY

ONCHANGE

ROWS

ONCLICK

STYLE

ONDBLCLICK

TABINDEX

ONFOCUS

TITLE

ONKEYDOWN

WRAP

End tag:

</textarea>; never omitted

Contains:

plain_text

Used in:

form_content

You may include plain text inside the <textarea> tag and its end tag. That default text must be plain text -- no tags or other special elements. The contents may be modified by the user, and the browser uses that text as the default value if the user presses a reset button for the form. Hence, the text content is most often included for instructions and examples:

Tell us about yourself: 
<textarea name=address cols=40 rows=4>
  Your Name Here
  1234 My Street
  Anytown, State Zipcode
</textarea>

9.7.1.2. The wrap attribute

Normally, text typed in the text area by the user is transmitted to the server exactly as typed, with lines broken only where the user pressed the Enter key. Since this is often not the action desired by the user, you can enable word wrapping within the text area. When the user types a line that is longer than the width of the text area, the browser automatically moves the extra text down to the next line, breaking the line at the nearest point between words in the line.

With the wrap attribute set to virtual, the text is wrapped within the text area for presentation to the user, but the text is transmitted to the server as if no wrapping had occurred, except where the user pressed the Enter key.

With the wrap attribute set to physical, the text is wrapped within the text area and is transmitted to the server as if the user had actually typed it that way. This the most useful way to use word wrap, since the text is transmitted exactly as the user sees it in the text area.

To obtain the default action, set the wrap attribute to off.

As an example, consider the following 60 characters of text that are being typed into a 40-character-wide text area:

Word wrapping is a feature that makes life easier for users.

With wrap=off, the text area will contain one line and the user will have to scroll to the right to see all of the text. One line of text will be transmitted to the server.

With wrap=virtual, the text area will contain two lines of text, broken after the word "makes." Only one line of text will be transmitted to the server: the entire line with no embedded newline characters.

With wrap=physical, the text area will contain two lines of text, broken after the word "makes." Two lines of text will be sent to the server, separated by a newline character after the word "makes."



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.