Chapter 13. Making Dynamic Pages with JavaScript

IN THIS CHAPTER

  • Trying out JavaScript

  • Understanding JavaScript

  • Using events to trigger scripts

  • Seeing elements as objects

  • Form Validation

  • Examining browser compatibility

  • JavaScript quick reference

Many people confuse JavaScript with Java. It's understandable, given the similarity in their names. But the two are not the same. Although some of JavaScript is somewhat similar to Java, Java is closer to C++ — all programming languages bear some degree of resemblance to one another. Java is a major language that is used for developing standalone programs, many of which are huge and extremely complex. JavaScript, on the other hand, is used to write short and simple programs that can run in Web browsers.

JavaScript's name came from Netscape licensing the Java name from Sun in order to capitalize on the Java craze at the time. JavaScript was originally called LiveScript.

Of course, you can use Java to write short and simple programs; many of the Java applets available to use on Web pages certainly fit this description. And you can also use JavaScript to create some incredibly intricate interactive programs on your Web pages. As with anything else on the Web, the limits are mainly up to you.

Trying Out JavaScript

Before we get into any of the details of how JavaScript works, let's see just how simple it can be. Type the following code into your HTML editor:

<HTML>
     <HEAD>
     <TITLE>JavaScript Is Great</TITLE>
     </HEAD>
<BODY onLoad="alert('Welcome to the war, ...

Get Creating Web Sites Bible, Third 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.