Reputation: 1321
I have used window.location in my code to see that if I login correctly, it will take me to home page, it shows the alert and correctly displays "password" but it doesn't direct me to the new page
I have already tried looking at this forum and youtube
<button onclick="check(this.form)"> Login </button>
<script>
function check(form) {
if(form.psw.value == "password")
{
home = true;
if(home == true) {
window.location = "destination.html";
}
alert(form.psw.value);
}else {
alert("Wrong Password. Try again or click Forgot Password to reset it.")
}
}
Expected Result is that I get directed to the destination.html page
Actual result is that I stay on my page with the alert "password"
Upvotes: 0
Views: 38
Reputation: 235
I think the problem is that you are trying to do two things at the same time, show an alert and redirect to 'destination.html'. I believe what is happening is ...the alert is shown before the redirect is completed which prevents the redirect action.
Upvotes: 1