Javascript Course


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

Alert

alert() displays a very basic notice box with a message inside it.
- Syntax:
window.alert('alert_text');
- 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>
window.alert('Welcome');
</script>
- The user will be presented with a small box containing only the message and a button marked OK, like next image.
Alert window

JS Confirm

The confirm() method 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.

Syntax:
window.confirm('Question')
- 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>
var ques = window.confirm('The result of 0+0 is 0?');
if (ques) alert('Corect');
else alert('Incorrect');
</script>
The confirm box will look like:
Confirm box

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.
Syntax:
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>
var msg = window.prompt('Write your name', 'Name');
alert('Hello '+ msg);
</script>
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

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used to add lists into <ul> and <ol> elements?
<dt> <dd> <li>
<ul>
 <li>http://coursesweb.net/html/</li>
 <li>http://coursesweb.net/css/</li>
</ul>
Which value of the "display" property creates a block box for the content and ads a bullet marker?
block list-item inline-block
.some_class {
  display: list-item;
}
Which instruction converts a JavaScript object into a JSON string.
JSON.parse() JSON.stringify eval()
var obj = {
 "courses": ["php", "javascript", "ajax"]
};
var jsonstr = JSON.stringify(obj);
alert(jsonstr);    // {"courses":["php","javascript","ajax"]}
Indicate the PHP class used to work with HTML and XML content in PHP.
stdClass PDO DOMDocument
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>';
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById("dv1");
echo $elm->nodeValue;    // CoursesWeb.net
Alert, Confirm and Prompt

Last accessed pages

  1. Mysql SELECT JOIN tables on two different Databases (4498)
  2. jQuery UI draggable - Drag elements (11448)
  3. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (142520)
  4. Using the Bone Tool (4253)
  5. Node.js Move and Copy Directory (20134)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (523)
  2. The Mastery of Love (65)
  3. CSS cursor property - Custom Cursors (62)
  4. Read Excel file data in PHP - PhpExcelReader (59)
  5. PHP-MySQL free course, online tutorials PHP MySQL code (44)