function confirm() { var r = confirm("Pre...">

Confirmation function does not work

*<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 the problem is. It does not work, but it is the same as in http://www.w3schools.com/js/js_popup.asp

+4
source share
5 answers
  • You call confirm() recursively and in an infinite loop
  • You have * at the beginning and end of the document.
  • As kennebec pointed out, you are rewriting window.confirm
  • In <body> you have a hanging end
</div>

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> 
+7
source

First, you rewrote window.confirm ... Then you invoke a new confirmation, forever, or until there is too much recursion ...

+2
source

Your function has the same name as the built-in window.confirm() function, so your function replaces it. Then in your function you call confirm() , which means that it calls itself recursively.

It should work if you just rename your function to another. (For example, the w3schools page you are linking to calls its "show_confirm" function.)

+2
source

You need to return the value from the confirm () function and return that value to the onclick handler if you are trying to use it to prevent sending.

IMO is a really bad idea to call your function β€œconfirm”, although since there is already a method called that way, and you can overwrite until the browser melts.

In addition, saying something β€œdoes not work”, not saying what he is doing and what you expect from him, makes it difficult to answer questions.

+1
source

confirm() is a predefined function in javascript, so you cannot use it for the name of one of your functions. This is a mistake, rename the function and it will work correctly.

Also remove * from the beginning and end.

0
source

All Articles