Приглашаем посетить
Добычин (dobychin.lit-info.ru)

Accepting Text Input

Previous Page
Table of Contents
Next Page

Accepting Text Input

To ask the user for a specific piece of information within a form, use the <input /> tag. This tag must fall between the <form> and </form> tags, but it can be anywhere on the page in relation to text, images, and other HTML tags. For example, to ask for someone's name you could type the following:

What's your first name? <input type="text" size="20" maxlength="30"
name="firstname" />
What's your last name? <input type="text" size="20" maxlength="30"
name="lastname" />

The type attribute indicates what type of form element to displaya simple one-line text entry box in this case. (Each element type is discussed individually in the following sections.)

The size attribute indicates approximately how many characters wide the text input box should be. If you are using a proportionally spaced font, the width of the input will vary depending on what the user enters. If the input is too long to fit in the box, most web browsers will automatically scroll the text to the left.

maxlength determines the number of characters the user is allowed to type into the text box. If someone tries to type beyond the specified length, the extra characters won't appear. You can specify a length that is longer, shorter, or the same as the physical size of the text box. size and maxlength are used only for type="text" because other input types (check boxes, radio buttons, and so on) have a fixed size.

Did you Know?

If you want the user to enter text without it being displayed on the screen, you can use <input type="password" /> instead of <input type="text" />. Asterisks (***) are then displayed in place of the text the user types. The size, maxlength, and name attributes work exactly the same for type="password" as for type="text". Keep in mind that this technique of hiding a password provides only visual protectionthere is no encryption or other protection associated with the password being transmitted.



Previous Page
Table of Contents
Next Page