Window confirm() Method - Display a confirmation box, and output what the user clicked: - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window confirm

Description

Window confirm() Method - Display a confirmation box, and output what the user clicked:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w ww. j  a  v  a  2s  . c o  m
    var txt;
    var r = confirm("Press a button!");
    if (r == true) {
        txt = "You pressed OK!";
    } else {
        txt = "You pressed Cancel!";
    }
    document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

Related Tutorials