Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!