HTML Textarea is the multiple line text entry element. It is used to let the users type amultiple lines of text which can spread to a few lines. The examples of data that can be entered in an HTML textarea are user’s address, comments, complaints, and other such details in a paragraph form. This control retains the newlines and spaces provided in the text. You cannot add HTML tags in an Textarea.
Syntax – HTML Textarea
A multiline textarea in an HTML form is created by using TEXTAREA tag. This is a paired tag where the text is given between the opening and closing <TEXTAREA> tags.
<TEXTAREA [other attributes]> text to be displayed as default</TEXTAREA>
Attributes- HTML Textarea
HTML Textarea control uses the following attributes.
ID
This attribute is used to give identification to the textarea in a web form element. The ID must be an alphanumeric string. The ID value for each field of web form must be unique. This ID is used in a script to manipulate the data entered by a user in the textarea.
NAME
The NAME attribute is used to give name to the textarea that is used to access its values by the associated php or asp script file since the data is passed as keyword-value pairs. It is like a variable name holding a value given by user.
ROWS
The ROWS attribute is used to define how rows of height the textarea is going to have as its vertical dimension. It’s the height of the textarea with which it is displayed to the visitor. If the user types more characters that fit in the height of the textarea then these excess characters will be automatically down scrolled. The extra characters can be accessed by pressing the down arrow key.
COLS
The COLS attribute is used to define how many columns of width the textarea is going to have as its horizontal dimension. It’s the width of the textarea with which it is displayed to the visitor. If the user types more characters that fit in the width of the textarea then these excess characters will be automatically moves to the next row if WRAP attribute is off.
WRAP
This attribute defines whether characters more than the width of the textarea have to be wrapped. The allowed values are OFF, HARD and SOFT.
- WRAP=”OFF” do not allow wrapping of data and all the text is added in one line and a vertical scroll will appear automatically.
- WRAP=”SOFT” (default) the text will not be sent with newline when it is submitted.
- WRAP=”HARD” the text carries newlines when the form is submitted and will work only when cols attribute is specified.
Example HTML TEXTAREA
<BODY> <FORM action="addperson.php" method="post"> Your Name <BR> <input type="text" Name="name" MAXLENGTH="50"> <BR> Email ID <BR> <input type="text" Name="email" SIZE="20"> <BR> Enter your comment <BR> <TEXTAREA ROWS="3" COLS="20" WRAP="OFF">This is the best experience I ever had on a shopping website</TEXTAREA> Enter your Experience <BR> <TEXTAREA ROWS="3" COLS="20" WRAP="SOFT">This is the best experience I ever had on a shopping website</TEXTAREA> <BR><BR> Enter your Feedback <BR> <TEXTAREA ROWS="3" COLS="20" WRAP="HARD">This is the best experience I ever had on a shopping website</TEXTAREA> </FORM> </BODY>