Use confirm method in if statement in JavaScript

Description

The following code shows how to use confirm method in if statement.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
<!--   www.ja va 2  s  .c om-->
var username = prompt("Type your name:", "");

if (confirm("Your name is: " + username + ". Is that correct?") == true )
{
document.writeln("Hello " + username);
}
else
{
document.writeln("Hi");
}
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use confirm method in if statement in JavaScript
Home »
  Javascript Tutorial »
    Browser »
      Browser Dialog
Javascript Tutorial Browser Dialog
Add quotation marks to alert box in JavaScr...
Create a Confirmation dialog in JavaScript
Get value from prompt dialog and display it...
Output the Confirmation dialog returns bool...
Prompt dialog with default value in JavaScr...
Show a confirm dialog in JavaScript
Show a find dialog with window.find() in Ja...
Show an alert dialog in JavaScript
Show the print dialog in JavaScript
Show the prompt() dialog in JavaScript
Use alert Boxes in JavaScript
Use alert dialog box to display the content...
Use confirm method in if statement in JavaS...