4

I have a problem with my website. When there is "333" in the input box (id textbox_text) website is supposed to redirect to the specified url, but instead nothing happens. Where is the problem?

    <script>
            function IsEmpty()
            {
            if(document.forms['frm'].textbox_text.value == "333")
             {
                window.location.href="martyna-lesniak.html";
            }
            else 
            {
                alert("Nieprawidłowe hasło!");
            }
        }
    </script>
    <div class="container">
        <form name="frm">
            <input type="password" name="password1" class="password-input" id="textbox_text" placeholder="Wpisz hasło">
            <input type="submit" name="submit" onclick="return IsEmpty();" value="Wysyłaj" class="button-input" />
        </form>
    </div>
2
  • Use window.location.replace(url). Href only works on click Commented Apr 26, 2020 at 1:14
  • Still nothing :/ Page just refreshes Commented Apr 26, 2020 at 1:30

3 Answers 3

6

You just have to return false; after your call to window.location.href="martyna-lesniak.html";.

Sign up to request clarification or add additional context in comments.

Comments

0

If you have the HTML that you need to refer in other folder that the actual html you need to put the path of the resource (html) the other thing is in the conditional you can put === to have a literal equal object

Comments

0

Try this

<script>
        function IsEmpty()
        {
        if(document.forms['frm'].textbox_text.value == "333")
         {

            window.location.href="martyna-lesniak.html";
            return false;
        }
        else 
        {
            alert("Nieprawidłowe hasło!");
        }
    }
</script>
<div class="container">
    <form name="frm">
        <input type="password" name="password1" class="password-input" id="textbox_text" placeholder="Wpisz hasło">
        <input type="submit" name="submit" onclick="return IsEmpty();" value="Wysyłaj" class="button-input" />
    </form>
</div>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.