Technical Training
JavaScript TutorialJavaScript Alert Box
JavaScript Alert Box
In this JavaScript tutorial, you will learn about JavaScript alert box along with code for placing the alert box when page is loaded.
There are three types of popup boxes that can be created using JavaScript. Depending on the needs of user, the programmer can create any of these types of popup boxes using JavaScript. Three kinds of popup boxes created using JavaScript are:
- Alert Box
- Confirm Box
- Prompt Box
Let us now learn how to create each of these popup boxes using JavaScript.
Alert Box:
This type of popup box is a dialog box used when a programmer wants to make sure that the information is passed to the user. The alert box pops up with an OK button which the user has to press to continue further.
General syntax of alert box is
alert(“textmessage”)
For example:
alert(“Exforsys”)
The above statement will display a dialog box with message Exforsys and a OK button.
The dialog box remains in view until the user presses the OK button.
When no text message is placed
alert()
This would display an empty dialog box with an OK button that the user must press to proceed.
It is also possible to display messages with values of variables in an alert box.
For example:
|
In the above script alert box displays the value of variable exam_score concatenated with a string.
The plus sign acts as a concatenation symbol.
Output of the above script as produced in a HTML page is shown below:

It is vital to understand that the alert box can be placed in different locations or events.
Depending on the placing of the alert box and based on the place of usage, the alert box will be activated.
For example,
- it is possible to place the alert box so that it pops up when a page is loaded.
- it is possible to place the alert box to be activated when a button is clicked.
Here is an example of JavaScript code for placing the alert box to be executed when a page is loaded.
|
Output of the above script as produced in a HTML page is shown below:

In the above example, message Exforsys pops up in the alert box when the page is loaded.
JavaScript Tutorial
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
- JavaScript Windows Object Properties Part II
- JavaScript Windows Object Properties Part I
- JavaScript DOM Window Object
- Working with JavaScript DOM Objects
- JavaScript Array Object Methods – Part II
- JavaScript Array Object
- JavaScript Array Object Methods – Part I
- JavaScript Boolean Object
- JavaScript OnError Event
- JavaScript Exception Handling – Part II
- JavaScript Exception Handling – Part I
- JavaScript Event Handler
- JavaScript Events Handling
- JavaScript Array Operations
- JavaScript Two Dimensional Arrays
- Passing values to JavaScript Function
- JavaScript Functions
- JavaScript Arrays
- JavaScript Iterative Structures - Part II
- JavaScript Iterative Structures - Part I
- JavaScript Math Object
- JavaScript Date Object
- JavaScript String Object
- JavaScript Objects
- JavaScript Confirm Box
- JavaScript Alert Box
- JavaScript Conditional Statements Part 2
- JavaScript Conditional Statements Part 1
- How to use JavaScript in HTML page
- JavaScript Variables
- JavaScript Features
- JavaScript Introduction







