Alert, Prompt and Confirm are predefined dialog windows, they belong directly to the JavaScript object "window".

1. Alert

Alert is a very basic notice box with a message inside it.
- The string of text will be displayed in the alert pop-up box. When an alert box pops up, the user will have to click "OK" to proceed.
- For example, the next script opens an Alert window with the message "Welcome".
<script type="text/javascript"><!--
- The user will be presented with a small box containing only the message and a button marked OK, like next image.
Alert window

2. Confirm

The confirm window displays a confirmation dialog box to the viewer, who must then click OK or Cancel to proceed.
A confirm box is often used if you want the user to verify or accept something.

- The confirm box displays the text "Question" and two buttons "OK" and "Cancel".
- If the user clicks "OK", the box returns True. If the user clicks "Cancel", the box returns False.
Aceasta fereastra este folosita pentru a fi executata o comanda cand este apasat butonul "OK" (returneaza TRUE) si alta comanda cand este apasat butonul "Cancel" (returneaza FALSE)
The next example opens a confirm window with the question "The result of 0+0 is 0?". If it's clicked "OK" it shows an Alert window with the message "Corect", but if it's clicked "Cancel" it opens an Alert window with the message "Incorrect".
<script type="text/javascript"><!--
var ques = window.confirm("The result of 0+0 is 0?");
if (ques) alert("Corect");
else alert("Incorrect");
The confirm box will look like:
Confirm box

3. Prompt

A Prompt box is used if you want the user to input information. Using this window, you can do things based on what the viewer enters into the text box at the prompt.
window.prompt("Message", DefaultValue)
- The "Message" is the text that will be shown above the text box. The "DefaultValue" argument will be the starting text inside the text box. If you don't want any text in the text box, leave this as an empty string.
- The dialogue will return a string containing the text typed by the user or "null" if the user didn't type anything:
The next example opens a Prompt dialog box.
<script type="text/javascript"><!--
var msg = window.prompt("Write your name", "Name");
The prompt window will look like:
Prompt window
- If the user clicks "OK" will display an Alert window with the name typed in the text box, if it's clicked "Cancel", the Alert will display "null".

Daily Test with Code Example

Which tag is used to add definition lists into a <dl> element?
<dt> <dd> <li>
  <dd> - Hyper Text Markup Language</dd>
  <dd> - Language for web pages</dd>
Which CSS property can hide an element on page, letting an empty space in its place?
display position visibility
#id {
  visibility: hidden;
Click on the event which is triggered when the mouse clicks on an object.
onclick onmouseover onfocus
document.getElementById("id").onclick = function(){
Indicate the PHP variable that contains the contents of both $_GET, $_POST, and $_COOKIE arrays.
if(isset($_REQUEST["id"])) {
  echo $_REQUEST["id"];
Alert, Confirm and Prompt

Last accessed pages

  1. Zuma Deluxe (37882)
  2. CSS3 Flexbox Container (40)
  3. Qwop (40212)
  4. Bike Mania2 (984)
  5. Auto Moto Games (7364)

Popular pages this month

  1. Qwop (7387)
  2. Drag Racer V3 (5115)
  3. Bubbles3 (2030)
  4. List with All the Games (1718)
  5. Flash Games - Free online Games (1605)