Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Confirm Box

A confirm box is typically used when you need the user to verify or approve something.

When a confirm box appears, the user must click either “OK” or “Cancel” to continue.

Clicking “OK” returns true, while clicking “Cancel” returns false.

Syntax

window.confirm(“sometext“);

The confirm() method can be used without the window prefix.

Example

if (confirm(“Press a button!”)) {
  txt = “You pressed OK!”;
else {
  txt = “You pressed Cancel!”;
}