HTML and CSS Reference
In-Depth Information
The alert message box is displayed using the alert() method. The structure is as follows:
alert("message to be displayed");
Each JavaScript command line generally ends with the semicolon, ; . Also, JavaScript is
case-sensitive , which means that there's a difference between uppercase and lowercase
characters and it will be important to be precise when typing JavaScript code.
In this Hands-On Practice you will create a simple script with an alert() message box.
Launch Notepad. Type the following XHTML and JavaScript code. Note that alert()
does not contain a space between alert and the opening parentheses.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" lang="en" xml:lang="en">
<title>JavaScript Practice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<h1>Using JavaScript</h1>
<script type="text/javascript">
<!-- <![CDATA[
alert("Welcome to my web page!");
// ]]> -->
<h2>When does this display?</h2>
Save this file as alert.html. Launch Firefox and load the alert.html file to test your page.
Notice that the first heading appears, and then the alert message pops up as shown in
Figure 14.8. After you click the OK button, the second heading appears. This illustrates
the top-down processing of the Web page and embedded JavaScript. The JavaScript
block is between the headings, and that's where the alert message appears as well.
Figure 14.8
JavaScript practice
alert.html displaying
alert message box
Search WWH ::

Custom Search