Creating Text Boxes

Text boxes can contain one line of free-form textthat is, anything that the visitor wants to typeand are typically used for names, addresses, and the like.

Figure 17.16. While it's essential to set the name attribute for each text box, you only have to set the value attribute when you want to add default values for a text box.

To create a text box:


If desired, type the label that will identify the text box to your visitor (for example, Name:).


Type <input type="text".


Type name="label", where label is the text that will identify the input data to the server (and your script).


If desired, type value="default", where default is the data that will initially be shown in the field and that will be sent to the server if the visitor doesn't type something else.


If desired, define the size of the box on your form by typing size="n", replacing n with the desired width of the box, measured in characters.


If desired, type maxlength="n", where n is the maximum number of characters that can be entered in the box.


Finish the text box by typing a final />.

Figure 17.17. Text boxes can be different sizes to accommodate different types of fields. We'll straighten these up in just a moment (on page 264).


  • Even if your visitor skips the field (and you haven't set the default text with the value attribute), the name attribute is still sent to the server (with an undefined, empty value).

  • The default for size is 20. However, visitors can type up to the limit imposed by the maxlength attribute. Still, for larger, multi-line entries, it's better to use text areas (see page 269).

HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: