Home > Blockchain >  How to redirect to specific URL depending on password entered?
How to redirect to specific URL depending on password entered?

Time:12-21

I have a password-protected button that will redirect a user to a specific URL when the password is entered. It works fine but what I want to do is depending on what password the user enters, they will be taken to a URL which corresponds to what they entered. Let's say 'test' was entered in the box, this will redirect users to 'test.com/test/test.html' but if the user entered 'test1' then they'll be redirected to 'test.com/test1/test1.html'. Is there any way to do this? This is my code:

<body>
  <div id="title">
    <span>WELCOME TO</span> <span style="font-size:80px"><br>
        AiZen</span>
  </div>
  <div >
    <button  id="HyperLink1" onclick="location.href='home.html';return ValidatePassword()"><span>Enter Now</span></button>
  </div>
  <script>
    function ValidatePassword() {
      var a = prompt("Enter the password. You know it right?", "");
      if (a == "test") {
        return true
      } else {
        alert("No match. Try again.")
      }
      return false
    }
  </script>
</body>

CodePudding user response:

Assuming that you don't have access to a backend app server, or that you don't want to use it for this, you can do something like

document.getElementById("name").addEventListener("input", function(e) {
      var val = e.target.value;
      var form = e.target.closest("form");
    //test.com/test1/test1.html
      form.action = "http://test.com/"   val   "/"   val   ".html";
      console.log("action: "   form.action);
    });
<form>
    <input name="name" id="name" />
    <input type="submit">
    </form>

  • Related