I am encountering an issue with my function regarding a login form validation using JSON data. The code seems to be working correctly, but only when I input the correct data immediately after refreshing the page. For example, if I enter an incorrect login/password combination, I receive an error, but then if I try again with the correct credentials, nothing happens.
Your assistance would be greatly appreciated. Below is the JavaScript code I am currently using:
//JSON validation
function validation(username, password){
var alert = document.getElementById("invalid-data");
data = JSON.parse(data);
for (var i=0; i < data.length; i++) {
if (username == data[i].login && password == data[i].password) {
window.open("panel.html", "_self");
} else {
alert.style.display = "block";
}
}
}
//Form validation
function getLoginInfo() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
validation(username, password);
}
var button = document.getElementById("login-button");
button.addEventListener("click", getLoginInfo);