HTML and CSS Reference
In-Depth Information
An input element with "text" as the value of the type element accepts any
text string that does not contain a line break. Other type attribute values cre-
ate text input ields with restrictions on what the user can enter:
url he input must be a valid URL, complete with protocol
and hostname parts.
email he input must represent an email address or a comma-
separated list of email addresses.
password he input is treated as a text ield, but the user's input is
obscured as it is entered.
number he input must represent an integer or a real number.
However, the default type for the input element is text , so if the type ele-
ment is missing or its value is unrecognized, the browser just creates an ordi-
nary text input ield. herefore, although having these nice built-in types is
convenient, you cannot rely on pre-HTML5 browsers to do the input checking
for you.
Example 2.25 shows the use of text input ields in a simple form. he
required attribute is added to some of the input elements to prevent the user
from leaving those ields blank. he value attribute is used to initialize the ield
requesting a URL and to indicate to the user that a full web address is being
requested. Most elements within a form permit the use of a value attribute to
set an initial value for the ield.
Within the form element, there must be some provision for users to submit
their entries. his is usually provided by an input element with the type attri-
bute's value set to submit, which creates a button. Likewise, an input element
with the type attribute's value set to reset gives the user a button that clears all
entries from the form's ields and starts over.
Example 2.25: A simple form with input elements
<!DOCTYPE html>
<html>
<head><title>Example 2.25</title></head>
<body style="padding: 0px 36px;">
continues
 
Search WWH ::




Custom Search