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>
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>
Share
Improve this question
asked Apr 26, 2020 at 1:11
ForcowiczForcowicz
1081 gold badge1 silver badge10 bronze badges
2
- Use window.location.replace(url). Href only works on click – Socrates Tuas Commented Apr 26, 2020 at 1:14
- Still nothing :/ Page just refreshes – Forcowicz Commented Apr 26, 2020 at 1:30
3 Answers
Reset to default 6You just have to return false;
after your call to window.location.href="martyna-lesniak.html";
.
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
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>