So I have been working on this little puzzle site and I want the correct password for the textfield to be inside the JS function. Now it does recognize the password already which is good but the issue is that when I try to use window.location.href = "https://www.google.com";
it does not redirect the page to new site. It only "refreshes" the site..
My script is as followed:
<script>
function validate() {
var password = document.forms["passwordform"]["password1"].value;
var realpassword = 'salaisuus'
if (password === realpassword) {
window.location.href = "http://www.google.com";
return true;
} else {
alert("Wrong password")
return false;
}
}
</script>
and the actual form is here:
<form id="passwordform" onSubmit="return validate()">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="floatingInput" name="password1" placeholder="whatwhat">
<label for="floatingInput">PASSWORD</label>
</div>
<button type="submit" class="btn btn-dark">TRY IT</button>
</form>
So as said, it does send the alert for wrong password, but the window.location.href
is not working. What am I missing here?