Chris
Chris

Reputation: 1321

Is there something I am doing wrong when using window.location to transfer webpages using javascript and html

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

Answers (1)

Khalid
Khalid

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

Related Questions