Dialog box

All JavaScript dialog box is a predefined function which is used for to perform different-different task. Some function are given below;
functionDiscription
alert()To give alert message to user.
prompt()To input value from used.
confirm()To get confirmation from user before executing some task.

Alert()

Alert function of java script is used to give an alert message to the user.

Alert function example

Example

<!doctype html>
<html>
<head>
<script>
function alertmsg()
{
alert("Alert function call");
}
</script>
</head>
<form>
<input type="button" value="Click Me" onclick="alertmsg()"/>
</form>
</html>

Result

prompt()

Prompt function of java script is used to get input from the user.

prompt() function example

Example

<!doctype html>
<html>
<head>
<script>
function alertmsg()
{
a=prompt("Enter your name:");
alert(a);
}
</script>
</head>
<form>
<input type="button" value="Click Me" onclick="alertmsg()"/>
</form>
</html>

Result

confirm()

confirm function of java script is used to get confirmation from user before executing some task.

confirm() function example

Example

<!doctype html>
<html>
<head>
<script>
function alertmsg()
{
a=prompt("Enter your name:");
confirm(a);
}
</script>
</head>
<form>
<input type="button" value="Click Me" onclick="alertmsg()"/>
</form>
</html>

Result