Jumat, 07 Juni 2024

alert confirm prompt in JavaScript

Window alert() method

window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog.

Type this following javascript code in your javascript editor, inside <script> tag.

window.alert("Hello world!");
// or you can type like this:
alert("Hello world!");

Window confirm() method

window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.

Type this following javascript code in your javascript editor, inside <script> tag.

if (window.confirm("Do you really want to leave?")) {
  window.open("exit.html", "Thanks for Visiting!");
}

Window prompt() method

window.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog.

Syntax

prompt(message, defaultValue)

The Number() method converts a value to a number. If the value cannot be converted, NaN is returned.

Type this following javascript code in your javascript editor, inside <script> tag.

const aNumber = Number(window.prompt("Type a number", ""));

Return value
A string containing the text entered by the user, or null.
When the user clicks the OK button, text entered in the input field is returned. If the user clicks OK without entering any text, an empty string is returned. If the user clicks the Cancel button, this function returns null.


dialogue box in javascript, dialog box in javascript, core javascript, javascript method, javascript editor, text editor

Related Post:

Tidak ada komentar:

Posting Komentar

Various Other Posts