I want to create a simple login system with the help of javascript. Unfortunately, the if statement doesn't work as I've intended it to. The page doesn't redirect when the enter key is pressed.
var objPeople = [
{studentid: "input1"},
{studentid: "input2"}
]
var input = document.getElementById("myInput");
input.addEventListener("keyup", function(event){
for(i = 0; i < objPeople.length; i++){
if (myInput == objPeople[i].myInput && event.keyCode === 13){
window.location.href = "www.google.com";
}
}
});
<html>
<head>
<script LANGUAGE="JavaScript" src="JavaScript.js"></script>
<title>aaa</title>
</head>
<body>
<input type="text" id="myInput">
</body>
</html>
See Question&Answers more detail:os