skip to Main Content

I have this code right here:

<html>
    <body style="color:white;background-color:#222222">
        <center>
            <br>
            <input type="text" id="username"> Username</input>
            <br>
            <input type="text" id="password"> Password</input>
            <br><br>
            <button onclick="test()">Submit</button>
            <p id="url"/>

            <script type="text/javascript">
                function test(){
                    var userInput = document.getElementById("username").value;
                    var userPass = document.getElementById("password").value;
                    document.getElementById("url").innerHTML = encodeURI('http://'+userInput+':'+userPass+'@'+window.location.hostname+':81/Home/');
                }
            </script>
        </center>
    </body>
</html>

It outputs an url that works. It logs me into my password-protected folders when I specify the right password.
Only problem, I want the “Submit” button to automaticly redirect me to the specified page instead of showing me the url.

I tried everything.
Please help.
Thanks.

2

Answers


  1. Please check this:

    function test(){
        var userInput = document.getElementById("username").value;
        var userPass = document.getElementById("password").value;
        location.href = encodeURI('http://'+userInput+':'+userPass+'@'+window.location.hostname+':81/Home/');
    }
    
    Login or Signup to reply.
  2. Instead of

    document.getElementById("url").innerHTML = etc 
    

    make it

    window.location.href = etc 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search