JavaScript Tutorial JavaScript Examples CSS Tutorial HTML Tutorial About Us

Lesson 3 : JavaScript Dialog


3.1 JavaScript Dialog

A dialog box that pops up on a web page will enhance the interactivity of the web page. It is normally used in advertising. A JavaScript dialog carries a message or a question that required some form of actions from the user, either clicking a button or pressing a key on the keyboard.In JavaScript, the syntax to launch a dialog is very simple, you just need to use the alert method. The structure is:

<html>
<head>

<script language="JavaScript">
windows.alert("Welcome to JavaScript Tutorial");
</script>

</head>
</html>

Adding this Script to a web page allows the user to see a popup dialog box that displays the message "welcome to JavaScript Tutorial"  as shown in the diagram below:

Figure 3.1

Click on the "Show Dialog" button to view the dialog box.

You can customize the format of the output using a backslash \ and "n". Let's change the line windows.alert("Welcome to JavaScript Tutorial") to window.alert"welcome to\nJavaScript\nTutorial"). The output will be displayed in three lines now, as shown below:

Click on the "Show Dialog Again" button to view the second dialog box.

Figure 3.2


❮ Previous Lesson Next Lesson ❯


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy