Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 469
SiriusKoder Avatar asked Dec 12 '22 08:12

SiriusKoder


1 Answers

  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>
like image 190
vol7ron Avatar answered Dec 23 '22 15:12

vol7ron