Java Reference
In-Depth Information
The hidden text box creates a Hidden object. This is available in the elements array property of the
Form object and can be manipulated in JavaScript like any other object, although you can actually set
its value only through its HTML defi nition or through JavaScript. As with a normal text box, its value is
submitted to the server when the user submits the form.
So why are hidden text boxes useful? Imagine you have a lot of information that you need to obtain
from the user, but to avoid having a page stuffed full of elements and looking like the control panel of
the space shuttle, you decide to obtain the information over more than one page. The problem is, how
do you keep a record of what was entered in previous pages? Easy — you use hidden text boxes and put
the values in there. Then, in the fi nal page, all the information is submitted to the server — it's just that
some of it is hidden.
The textarea Element
The <textarea/> element allows multi-line input of text. Other than this, it acts very much like the text
box element.
However, unlike the text box, the textarea element has its own tag, the <textarea> tag. It also has two
additional attributes: cols and rows. The cols attribute defi nes how many characters wide the text
area will be, and the rows attribute defi nes how many character rows there will be. You set the text
inside the element by putting it between the start and closing tags, rather than by using the value attri-
bute. So if you want a <textarea/> element 40 characters wide by 20 rows deep with initial text Hello
World on the fi rst line and Line 2 on the second line, you defi ne it as follows:
<textarea name=”myTextArea” cols=”40” rows=”20”>Hello World
Line 2
</textarea>
Another attribute of the <textarea/> element is the wrap attribute, which determines what happens
when the user types to the end of a line. The default value for this is soft, so the user does not have to
press Return at the end of a line, though this can vary from browser to browser. To turn wrapping on,
you can use one of two values: soft and hard. As far as client-side processing goes, both do the same
thing: they switch wrapping on. However, when you come to server-side processing, they do make a
difference in terms of which information is sent to the server when the form is posted.
If you set the wrap attribute on by setting it to soft, wrapping will occur on the client side, but the car-
riage returns won't be posted to the server, just the text. If the wrap attribute is set to hard, any carriage
returns caused by wrapping will be converted to hard returns — it will be as if the user had pressed
the Enter key, and these returns will be sent to the server. Also, you need to be aware that the carriage-
return character is determined by the operating system that the browser is running on — for example,
in Windows a carriage return is \r\n, whereas on a Macintosh the carriage return is \r and on Unix a
carriage return is \n. To turn off wrapping client-side, set wrap to off.
The Textarea object created by the <textarea/> element has the same properties, methods, and
events as the Text object you saw previously, except that the text area doesn't have the maxlength attri-
bute. Note that there is a value property even though the <textarea/> element does not have a value
attribute. The value property simply returns the text between the <textarea> and </textarea>
tags. The events supported by the Textarea object include the onkeydown, onkeypress, onkeyup, and
onchange event handlers.
Search WWH ::




Custom Search