Linked Questions

Popular Questions

Problem: Allow a user input and wait until a user input is received. If the user inputs matches then it allows the user to visit the website. Otherwise, you will be navigated to the error.html.

I have tried the following javascript code.

var code = prompt("Please enter code: ")

function myfunction(code) {
  if (code !=123) {
    window.alert("error has occured.");
    window.location.href="error.html";
  }
}

The expected results should be the the prompt allows enough time and to enter the authorized code, if successful we will the page content.

The function is loading correctly but it doesnt allow enough time to enter the passcode because after a couple of seconds it automatically redirects to error.html. Is this because of the body onload?

If everybody can suggest any extra validation i could that could be added i would appreciate it.

Related Questions