HTML (Web) Forms

As previously mentioned, there are two main methods by which you can interact with an online application running within your browser: click a link or submit a form. Clicking a link can request a page from the Web server, and if the application developer included data in a query string, clicking the link also sends that data. However, when you fill out a form and submit it, you have a much richer opportunity to send data to the Web server. Although some of the form fields may be preset (such as data in a query string) others (such as text and textarea fields) give you a great deal of control over the data you send. HTML forms are therefore used extensively to create user interaction capability that mimics the kind of interaction displayed in desktop applications.

HTML Form Elements

The HTML specification describes HTML elements related to forms, including the <form> element (begins and ends a form), the <input> element (makes several types of form field, including text fields, radio buttons, submit buttons, and so on), the <textarea> element (makes a text field with multiple columns and line), and the <select> element (makes drop down and static list boxes).

Each of these elements also has attributes. For example, the <form> element includes an attribute named method. The method attribute can be set to post (like this: method="POST") within the beginning form tag, and it makes the HTTP request's method be POST when the form is submitted.

Although it's common to refer to an HTML element as a tag, the term tag refers only to the beginning or ending HTML delimiter. For example, <p> is the beginning tag of the HTML element P (for paragraph) and </p> is the ending tag of this element. Together, the <p> and </p> tags make up the P element. By the way, the text between them (that is displayed in your browser as a paragraph) is their content.

When properly written, HTML form elements combine to create a very powerful means of user interaction for online applications. In the following sections each form field element and its attributes are discussed in detail.