HTML and CSS Reference
In-Depth Information
it is to show you what is possible in the most up-to-date web browsers and what to ex-
pect, we hope, in the coming iterations of browsers that are still catching up. It is the
road ahead, whether that is demonstrated by Safari, Chrome, Opera, Firefox, or Internet
Text input
A text input is used, unsurprisingly, for gathering typed text input. This is the default
type the input uses, and it is likely the most common input you have encountered. It is
a single-line control and normally appears in the form of a rectangular box with an inset
border, as shown in Figure 4-2 .
Figure 4-2. A text input showing some content entered into the input
The allowed length of the input string can be specified with the addition of a
maxlength attribute, which takes a numerical value equating to the maximum number
of allowed characters. There is not a direct feedback mechanism provided in the event
that the user tries to insert more than the allowed number of characters—the form con-
trol just ceases to accept extra characters and will truncate an overlong string if such a
string is pasted into the control. If you want to alert users that they've run out of room,
you'll need to use JavaScript.
Note The maxlength attribute isn't foolproof; longer lengths of text can be added
to a text input via JavaScript, for instance, and this text would be submitted to the server
without being truncated. To limit the length of text submitted with complete certitude,
the length would need to checked on the server as well.
You can also include a value attribute that presets the content of the text control:
<input type="text" name="data" value="Default text" />
The text entered into the value attribute will appear inside the text field when the
page loads, as shown in Figure 4-2 .
Note Using the value attribute is a way to include default data that gets submitted
if the user doesn't update the input's value before submitting the form. The value at-
tribute has also traditionally been the way to prompt the user on what to type into a
text field. This is such a common need in fact that HTML5 has added an attribute for
Search WWH ::

Custom Search