Search code examples
javascripthtmlfunctionconfirm

confirm function is not working


*<html>
<head>
<title>practise</title>
<script type="text/javascript">
function confirm() {
    var r = confirm("Press the button");
    if (r == true) {
        alert("You are right");
    } else {
        alert("You are wrong");
    }
}

</script>
</head>

<body>
        <input type="button" name="submit" value="showtime" onclick="confirm()"/>
    </div>
</body>
</html>*

I want to know what's the problem. It is not working but it is the same as in http://www.w3schools.com/js/js_popup.asp


Solution

    1. You are recursively calling confirm() and it's in an infinite loop
    2. You have a * at the beginning and end of the document
    3. As kennebec pointed out, you're overwriting window.confirm
    4. You have a hanging end </div> in the <body>

    http://jsfiddle.net/cvyyL/

    <html>
       <head>
          <title>practise</title>
          <script type="text/javascript">
             function show_confirm() {
                var r = confirm("Press the button");
                if (r == true) {
                   alert("You are right");
                } else {
                   alert("You are wrong");
                }
             }    
          </script>
       </head>
       <body>
          <input type="button" name="submit" value="showtime" onclick="show_confirm()"/>
       </body>
    </html>