Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda