HTML Forms
The HTML <form>
element, and the various form input elements, such as <input>
, <select>
, and <button>
, have an important place in
client-side programming. These HTML elements date from the very
beginning of the Web and predate JavaScript itself. HTML forms are the
mechanism behind the first generation of web applications, which
required no JavaScript at all. User input is gathered in form
elements; form submission sends that input to the server; the server
processes the input and generates a new HTML page (usually with new
form elements) for display by the client.
HTML form elements are still a great way to gather input from the user, even when form data is processed entirely by client-side JavaScript and never submitted to the server. With server-side programs, a form isn’t useful unless it has a Submit button. In client-side programming, on the other hand, a Submit button is never necessary (though it may still be useful). Server-side programs are based on form submissions—they process data in form-sized chunks—and this limits their interactivity. Client-side programs are event based—they can respond to events on individual form elements—and this allows them to be much more responsive. A client-side program might validate the user’s input as she types it, for example. Or it might respond to a click on a checkbox by enabling a set of options that are only meaningful when that box is checked.
The subsections that follow explain how to do these kinds of things with HTML ...
Get JavaScript: The Definitive Guide, 6th Edition 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.