All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Confirm Box In JavaScript

Last Updated : Mar 11, 2024

Confirm Box In JavaScript

In this article we will show you the solution of confirm box in JavaScript, an action can be confirmed with the confirm method in JavaScript by invoking an action confirmation dialog.

An OK button and a Cancel button appear in a confirmation dialog using a window object.

In case the user selects OK, the execution of the function will continue; if the user selects Cancel, the execution of the block code will be aborted.

JavaScript confirm() displays a confirmation dialogue window with OK, Cancel, and a specific message for the user to confirm.

Step By Step Guide On Confirm Box In JavaScript :-

<!DOCTYPE html>
<html>
<head>
    <title>
        Window confirm() Method
    </title>
</head>
<body style="text-align: center;">
    <h1 style="color:green;">
            TalkersCode
        </h1>
    <h2>
            Window confirm() Method
        </h2>
    <p>Click the button to display a confirm box.</p>
    <button onclick="Talkers()">Click me!</button>
    <script>
        function Talkers() {
            confirm("Press OK to close this option");
        }
    </script>
</body>
</html>
  1. We start by writing <HTML>, which tells the browser what HTML version we're using. Tags are the beginning of HTML documents.
  2. In order to explain the project's heading, we must use the <head> tag. They are now open and there are also </title> and </head>. In External style sheets, the step-by-step tag can either be used as a full URL or as a path relative to the current web page.
  3. This is followed by the <body> tag that defines the body of the webpage. This is where all the content for the website is written.
  4. Then we use stylesheet for creating a Can SS file.
  5. Then we use onclick directive for detecting click events and an ng-class directive for adding up and down arrows. ng-click and ng-class directives contain a function that takes the key name as a parameter.
  6. Then we added an HTML page with a <script> tag. The script tag explains the source code we used for the JavaScript google API run and the file we used that or the code.
  7. After that </script></body></html> and code should be executed after closing all tags.

Conclusion :-

The confirm() method will display a dialog box with a custom message that you can specify as its argument.

It’s similar to the JavaScript alert() method, but the difference is that confirm() will have two buttons instead of one.

I hope this article on confirm box in JavaScript helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪