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.
HANDS-ON PRACTICE 14.1
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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>JavaScript Practice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Using JavaScript</h1>
<script type="text/javascript">
<!-- <![CDATA[
alert("Welcome to my web page!");
// ]]> -->
</script>
<h2>When does this display?</h2>
</body>
</html>
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