var objLogin = [{
fname: "sastry",
book: "sastry"
}, {
fname: "laxman",
book: "laxman"
}, {
fname: "visali",
book: "visali"
}]
function storeData() {
var userName = document.getElementById("fname").Value;
var userPasswd = document.getElementById("book").Value;
for (i = 0; i < objLogin.length; i++) {
if (userName == objLogin[i].fname && userPasswd == objLogin[i].book) {
console.log(userName + "Is logged in!!");
return;
} else {
console.log("Incorrect username or password");
}
}
}
When accessing the value of an input field, you should use value
(lower case "v").
var userName = document.getElementById("fname").value;
Also, it's great to cache your element references, like this:
const userNameInput = document.getElementById("fname");
const userPasswdInput = document.getElementById("book");
function storeData() {
const userName = userNameInput.value;
const userPasswd = userPasswdInput.value;
for (i = 0; i < objLogin.length; i++) {
if (userName === objLogin[i].fname && userPasswd === objLogin[i].book) {
console.log(userName + "Is logged in!!");
return;
} else {
console.log("Incorrect username or password");
}
}
}