W3Schools.com

Window confirm() Method

Window Object Reference Window Object

Definition and Usage

The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.

This method returns true if the visitor clicked "OK", and false otherwise.

Syntax

confirm(message)


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The confirm() method is supported in all major browsers.


Example

Example

Display a confirm box, and alert what the visitor clicked:

<html>
<head>
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
  {
  alert("You pressed OK!")
  }
else
  {
  alert("You pressed Cancel!")
  }
}
</script>
</head>
<body>

<input type="button" onclick="disp_confirm()" value="Display a confirm box" />

</body>
</html>

Try it yourself »


Window Object Reference Window Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE