0

I am trying to write a code to match username and password. If both are right, it must be redirected to a new page and if it is wrong, it must give an alert message. When the password is correct and when I click on submit, it open the success message in a new tab, i want it to be displayed in the same tab.

    function redirectPage(form) {
    if (form.uname.value == 'test' && form.uname.value == 'test') {
       window.open('login.html');
    } else {
      alert("Wrong Credentials, Try again")
    } 

PS

       window.open('login.html','_self');

isnt working

1 Answer 1

1

Use this

window.location.replace("login.html");
Sign up to request clarification or add additional context in comments.

4 Comments

Tried, That isn't working too. It just refreshes my current page.
You have to be on a different page and add this code. When the condition is reached, it will redirect to "login.html"
The initial code is on "index.html" and when this line is reached, it should be redirected to "login.html"
There is something else going on on your code. It should work perfectly. Please post your rest of the HTML and Javascript on the page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.