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
- 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>
<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>
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.)
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.