Adding an Input Textbox
Input textboxes are used for a number of form needs, including any time you want someone to type out his name, address, and so forth. To create a textbox, you use the input element along with the type attribute and a value of text (see Example 5-2).
Example 5-2. Adding input textboxes
As Figure 5-1 shows, using input with the type attribute for a text input generates a familiar-looking form.
<form method="get" action="http://www.myserver.com/cgi-bin/mailscript/">
First Name: <input type="text" /><br />
Last Name: <input type="text" /><br />
Phone: <input type="text" />
</form>
Figure 5-1. Form inputs with text.
Example 5-3. Identifying text input with name and id
The next step is to set the size of the textbox. Using the size attribute, you can provide a width for each field. You can also set the number of characters that the text input will accept, and this is accomplished using the maxlength attribute (Example 5-4).
<form method="get" action="http://www.myserver.com/cgi-bin/mailscript/">
First Name: <input type="text" name="firstname" id="firstname" /><br />
Last Name: <input type="text" name="lastname" id="lastname" /><br />
Phone: <input type="text" name="phone" id="phone" />
</form>
Example 5-4. Modifying text input with size and maxlength
Wherever maxlength is set to 0, the number of characters that can be entered is not restricted; those that have specific integers will be limited to that number. Figure 5-2 shows the sized text fields, which are longer than those in 5-1.
<form method="get" action="http://www.myserver.com/cgi-bin/mailscript/">
First Name: <input type="text" name="firstname" id="firstname" size="25"
maxlength="40" /><br />
Last Name: <input type="text" name="lastname" id="lastname" size="25"
maxlength="40"/><br />
Phone: <input type="text" name="phone" id="phone" size="15" maxlength="0" />
</form>
Figure 5-2. Sizing input fields and modifying character width.
<input type="password" name="password" id="password" size="15" />