Textarea Fields

Textareas are the one form field type that doesn't use the input tag but instead has a tag of its own. This means that textareas behave somewhat differently than other form fields.

For a start, textareas are the only form fields that allow multiple lines of input. They also behave differently in that there is no attribute that you can attach to a textarea that will limit the amount of text that can be typed into it, instead you will need to add validation to the script that processes the form to test if the maximum allowable text input has been exceeded. Finally, instead of using a value attribute to supply the content to initially display in the field the textarea instead uses a closing tag and has the field content placed between the tags.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<h1>Textarea Fields</h1>
<form action="#">
<textarea rows="5" cols="30" id="txt" name="txt">
initial value
goes here

Here's what the Textarea Form page looks like in your web browser.

The id and name attributes serve the same purpose as we are already familiar with for other form fields to allow the field to be referenced both within the web page and by the script on the server that will subsequently process the form. For example if we were to add a label to the field we can associate the label with the textarea by referencing the id.

The cols and rows attributes are required in order to specify how big that you want the textarea to be.

Within a textarea is one place where starting a new line in your HTML does make a difference as the content between the textarea tags is treated as plain text displayed within the field exactly as shown. Any ampersands, less than, and greater than symbols to be displayed within the textarea should be replaced by their entity code equivalents in order to avoid terminating the textarea early.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow