How to use Confirmation Dialog Box in JavaScript

In this article we will discuss about how to make Confirmation Dialog Box in JavaScript.
  • 2307

JavaScript supports three types of  DialogBox one of which is confirmation DialogBox. This DialogBox is used to ask whether the user want to continue or not and it shows two buttons Ok and Cancel. To use the Confirmation Dialog Box we will use confirm() method in JavaScript and when the user click on Ok button then it will return true and if user will click on Cancel button the conform() method will return false.

JavaScript Code:

<html>

<head>

    <script type="text/javascript">

<!--

        function confirmation() {

            var value = confirm("Do you want to continue ?");

            if (value == true) {

                alert("You want to continue!");

                return true;

            } else {

                alert("You do not want to continue!");

                return false;

            }

        }

//-->

    </script>

</head>

<body>

    <p>

        Click this button to see the result:

    </p>

    <form>

    <input type="button" value="Click" onclick="confirmation();" />

    </form>

</body>

</html>

Output:

Image33.jpg

Image34.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here
 
© 2019 DotNetHeaven. All rights reserved.