JavaScript alert
The alert method gives you a quick and easy way to show a short message to the user. An alert makes one of the built in model dialogs, which expects one parameter, a string value that is displayed at the top of the window as the message for the user.
The following illustration is going to show an alert box as soon as the page loads on the face of the window it will display " welcome to my web site"
Run code | View code
Process
Show the dialog - alert method of the window
Events
The loaded document - body onload event
Input
The string displayed on the dialog - welcome to my web site
Event Trigger
The onload event of the body element in the document will call the alert method of the window object and show the model dialog that will display the string value on it.
The Solution
Define the body tag
<body>
Register the onload of the body element.
<body onload="">
Make the onload event call the window's alert method
<body onload="alert()">
Give the alert method the string parameter
<body onload="alert(welcome to my web site)">
Surround the string value with single quotes since double quotes have already been used
<body onload="alert('welcome to my web site')">
Usefulness
The alert method is useful when you want to show critical information to the user about the state of a web application. Critical means the application cannot continue as normal because the user has not performed an action in the accepted way. For example an error occurred, the user performed an invalid operation, A form's data cannot be sent to the server because there are missing entries etc.
The alert method also comes in handy when debugging, see the debug section for more information.
Run Code | View Code
See also Using prompt | Using confirm | Making windows
Using the status bar
|
Changing the background color of the document
|
Changing the content of a document
|
Using prompt
|
Using confirm
|
Changing the URL of a window Manually
|
Querying a text field's value
|
Checking the selected value of a select object
|
Checking if a checkbox is selected
|
Checking if a radio button is selected in a group
|
Making a rollover
|
Preloading images
|
Getting the time
|
Using setTimeout/setInterval
|
Making windows
|
Making cookies
JavaScript Tutorial Home