Chapter 9. Enhancing Web Forms
Since the earliest days of the Web, forms have made it possible for Web sites to collect information from their visitors. Forms can gather email addresses for a newsletter, collect shipping information to complete an online sale, or simply receive visitor feedback. Forms also require your siteâs visitors to think: read labels, type information, make selections, and so on. Since some sites depend entirely on receiving form dataâAmazon wouldnât be in business long if people couldnât use forms to order booksâWeb designers need to know how to make their forms as easy to use as possible. Fortunately, JavaScriptâs ability to inject interactivity into forms can help you build forms that are easier to use and ensure more accurate visitor responses.
Understanding Forms
HTML provides a variety of tags to build a Web form like the one pictured in Figure 9-1. The most important tag is the <form> tag, which defines the beginning (the opening <form> tag) and the end (the closing </form> tag) of the form. It also indicates what type of method the form uses to send data (post or get), and specifies where on the Web the form data should be sent.
You create the actual form controlsâthe buttons, text fields, and menusâusing either the <input>, <textarea>, or <select> tags. Most of the form elements use the <input> tag. For example, text fields, password fields, radio buttons, checkboxes, and submit buttons all share the <input> tag, and you specify which ...
Get JavaScript: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.