Been reading some JavaScript tutorials and attempted to make a simple login system. I used the following code for this purpose. The alert line properly executes but redirection line doesn't seem to produce any results.
Question: How can I make it work? What is wrong with the code?
Note: I am aware that this is not a secure login system. I just need it to properly redirect when different conditions are met.
I also tried different syntaxes for redirection line (removing quotes, parentheses, etc.). None of them seemed to work… in case this is just a syntax error.
Code:
<form name="loginForm" onsubmit="loginCheck()" method="post">
<input type="text" name="userName"><br>
<input type="text" name="passWord"><br><br>
<input type="submit" value="Login">
</form>
<script>
function loginCheck() {
var usr=document.loginForm.userName.value;
var psw=document.loginForm.passWord.value;
var username="admin";
var password="admin";
if ((usr==username) && (psw=password)) {
alert ("True Info");
window.location.href ("http://www.google.com");
return true;
}
else {
alert ("False Info");
window.location.href ("http://www.google.com");
return false;
}
}
</script>