What JavaScript Can DoThere are many things that you can do with JavaScript to make your Web pages more interactive and provide your site's users with a better, more exciting experience. JavaScript lets you create an active user interface, giving the users feedback as they navigate your pages. For example, you've probably seen sites that have buttons that highlight as you move the mouse pointer over them. That's done with JavaScript, using a technique called a rollover (Figure 1.2). Figure 1.2. A rollover is an image that changes when you move the mouse pointer over it.
You can use JavaScript to make sure that your users enter valid information in forms, which can save your business time and money. If your forms require calculations, you can do them in JavaScript on the user's machine without any server-side processing. That's a distinction you should know: programs that run on the user's machine are referred to as client-side programs; programs running on the server (including things called CGIs; more on them later) are called server-side programs. With JavaScript, you have the ability to create custom HTML pages on the fly, depending on actions that the user takes. Let's say that you are running a travel site, and the user clicks Hawaii as a destination. You can have the latest Hawaii travel deals appear in a new window. JavaScript controls the browser, so you can open up new windows, display alert boxes, and put custom messages in the status bar of the browser window. Because JavaScript has a set of date and time features, you can generate clocks, calendars, and timestamp documents. You can also deal with forms, set cookies, build HTML pages on the fly, and create Web-based applications. |