Confirm Dialog Boxes in Javascript  

The Javascript confirm alert dialog box differs from a regular alert dialog box in that it provides two choices to the user, OK and CANCEL. When you click the “OK” button it returns true otherwise it returns false.

0 725 Technology | Javascript
Wed Dec 26 , 2018

A confirm dialog box allows user to confirm or cancel an action. They alert you of potentially objectionable material. You can create confirm dialog boxes with the confirm() method.

Syntax

confirm("message")

Example



<html>  
<title>JavaScript Confirm Dialog Box</title>  
<head>
<script language="javascript"> 
function fn_confirm()
{ 
    var result = confirm("Click OK or Cancel to Continue");     
    if(result == true)  
    {  
        document.write("You clicked OK");  
    }  
    else  
    {  
        document.write("You clicked Cancel");  
    } 
} 
</script>
</head>  
<body>  
  
<form>
<input type="button" value="Click Confirm Box" onClick='fn_confirm()'>
</form>

</body>  
</html> 



Output



Subscribe & Get Regular Updates On Your E-mail