Java Reference
In-Depth Information
7
HTML Forms: Interacting
with the User
Web pages would be very boring if you could not interact with or obtain information from the user,
such as text, numbers, or dates. Luckily, with JavaScript this is possible. You can use this information
within the web page, or it can be posted to the web server where you can manipulate it and store
it in a database if you wish. This chapter concentrates on using the information within the web
browser, which is called client-side processing.
You're quite accustomed to various user interface elements. For example, the Windows operating
system has a number of standard elements, such as buttons you can click; lists, drop-down list
boxes, and radio buttons you can select from; and boxes you can check. The same applies with
any graphical user interface (GUI) operating system, whether it's a Mac, Unix, or Linux system.
These elements are the means by which you now interface with applications. The good news is
that you can include many of these types of elements in your web page — and even better, it's
very easy to do so. When you have such an element — say, a button — inside your page, you can
then tie code to its events. For example, when the button is clicked, you can fi re off a JavaScript
function you created.
It's important to note at this point that the elements discussed in this chapter are the common ele-
ments made available by HTML, and not ActiveX elements, Java Applets, or plug-ins. You'll look
at some of these in Chapter 13.
All of the HTML elements used for interaction should be placed inside an HTML form. Let's start
by taking a look at HTML forms and how you interact with them in JavaScript.
HTML Forms
Forms provide you with a way of grouping together HTML interaction elements with a common
purpose. For example, a form may contain elements that enable the input of a user's data for regis-
tering on a web site. Another form may contain elements that enable the user to ask for a car insur-
ance quote. It's possible to have a number of separate forms in a single page. You don't need to
Search WWH ::




Custom Search