0

I am trying to make a password login page but when you get the password correct, it just alerts the person that it is correct. But I want it to alert and to redirect to another page. For example, google.com. Here is my code, any help would be appreciated.

// Function to check Whether both passwords 
// are same or not. 
function checkPassword(form) {
    password = form.pass.value;
    correct = "admin";

    // If password not entered 
    if (password == '')
        alert("Please enter Password");

    // If confirm password not entered 
    else if (correct == '')
        alert("Please enter confirm password");

    // If Not same return False.     
    else if (password != correct) {
        alert("\nPassword is incorrect. Please try again...")
        return false;
    }

    // If same return True. 
    else {
        alert("Password is correct, press okay to continue.")
        return true;
    }
}

I am very new to coding and got this off of a YouTube Video so I literally don't know anything about JavaScript but I do know about HTML and CSS.

DevOffline
  • 77
  • 7

1 Answers1

0

Use the window.location.href to point to the url you want to proceed to. I have modified your example to redirect to www.google.com if the password is right

// Function to check Whether both passwords 
// are same or not. 
function checkPassword(form) {
  password = form.pass.value;
  correct = "admin";

  // If password not entered 
  if (password == '')
    alert("Please enter Password");

  // If confirm password not entered 
  else if (correct == '')
    alert("Please enter confirm password");

  // If Not same return False.     
  else if (password != correct) {
    alert("\nPassword is incorrect. Please try again...")
    return false;
  }

  // If same return True. 
  else {
    alert("Password is correct, press okay to continue.")
    window.location.href = 'https://www.google.com'
  }
}
zana
  • 304
  • 1
  • 6
  • It doesn't seem to work. Does it only work if it is hosted on a server? Because I am viewing via Google Chrome. – DevOffline May 29 '20 at 21:33