Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
confirm cancel button not working for this simple code

The confirm/cancel button is not working, I don't know what the issue is.

Even after clicking the confirm box cancel it's still directing me to another page.

<html>
    <head>
        <title>password</title>
    </head>
    <body>
        <script type="text/javascript">
            function f() {
                if (myform.password.value == "") {
                    window.alert("you need to enter your password");
                } else {
                    window.confirm("are you sure u want to proceed");
                    window.location =' https://www.facebook.com/';
                }
            }
        </script>
        <center>
            <h1>confirm password page</h1>
            <form id="myform">
                Enter the Password
                <input type="password" id="password" value="">
                <input type="button" id="continue" value ="continue" onclick="f()">
            </center>
        </form>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can do

if(window.confirm("are you sure u want to proceed")) {
      // Proceed to next page
}

The confirm() method displays a dialog box with a message, an OK button, and a Cancel button.

The confirm() method returns true if the user clicked "OK", otherwise false.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Window.confirm() returns a boolean.

  • if ok clicked then true.
  • if cancel clicked then false.

So you have to handle like a if-else block.

if(window.confirm("are you sure u want to proceed")){
// your redirection logic here.
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

I changed it

function f(){
  if(myform.password.value==""){
    window.alert("you need to enter your password");
  }
  else{
    if (window.confirm("are you sure u want to proceed")) {
      window.location =' https://www.facebook.com/';
    }
  }
}
<center>
  <h1>confirm password page </h1>
  <form id="myform">
    Enter the Password<input type="password" id="password" value="">
    <input type="button" id="continue" value ="continue" onclick="f()">
  </form>
</center>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda