JavaScript Tutorial JavaScript Examples JQuery Tutorial CSS Tutorial HTML Tutorial About Us

Lesson 3 : JavaScript Dialog

3.1 JavaScript Dialog

A JavaScript popup 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 script is as follows:

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

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")


window.alert("welcome to\nJavaScript\nTutorial")

The output will be displayed in three lines now, as shown below:

Figure 3.2

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

❮ Previous Lesson Next Lesson ❯

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