codescracker
javascript

JavaScript confirm Box



« Previous Tutorial Next Tutorial »

The confirm box in JavaScript is used to display a message and return a true or false value.

JavaScript confirm Box Example

Here is an example demonstrates confirm box in JavaScript:

<!DOCTYPE HTML>
<html>
<head>
   <title>JavaScript confirm Box</title>
</head>
<body>

<h3>JavaScript confirm Box Example</h3>
<script type="text/javascript">
   
   var checkval = confirm("Are you sure to delete this file ?");
   if(checkval)
      document.write("Welcome to codescracker.com! <br/>You have successfully deleted the file.");
   else
      document.write("Welcome to codescracker.com! <br/>The file is not deleted.");
   
</script>

</body>
</html>

Here are some sample outputs of the above JavaScript confirm box example. This is the initial output produced by the above JavaScript code:

javascript confirm box

This is the output after pressing OK button:

javascript confirm box example

This is the output after pressing Cancel button:

confirm box javascript

JavaScript Online Test


« Previous Tutorial Next Tutorial »



© Copyright 2021. All Rights Reserved.

CodesCracker