let userSignedIn = false;
// Function to handle login form submission
function handleLogin(event) {
event.preventDefault(); // Prevent form submission
// Get input values
var email = document.getElementById("login-email").value;
var password = document.getElementById("login-password").value;
// Retrieve user data from local storage
var storedUserData = JSON.parse(localStorage.getItem('userData'));
// Login page confirmation
if (storedUserData && storedUserData.email === email && storedUserData.password === password) {
// Redirect or display a message indicating successful login
alert("Login Successful!!");
userSignedIn = true;
window.location.href = "home.html";
updateLoginLogoutButtons()
} else {
// Display an error message indicating invalid credentials
alert("Wrong Password or Bearname. Please try again.");
}
}
// Function to update login/logout buttons based on login status
function updateLoginLogoutButtons() {
if (userSignedIn==true)
{
// User is logged in
document.getElementById("openModalBtn").style.display = "none"; // Hide login button
document.getElementById("logoutBtn").style.display = "inline-block"; // Show logout button
}
else if (userSignedIn==false)
{
// User is not logged in
document.getElementById("openModalBtn").style.display = "inline-block"; // Show login button
document.getElementById("logoutBtn").style.display = "none"; // Hide logout button
}
}
First of all this is my first time using stack overflow + english is not my first language so i am sorry for any inconvenience.
This is my javascript code for my login and logout button project. I’ve made sure that theres no error in naming or assigning from html to js file. The thing is my logout button wont come out after i successfully logged in. Can anyone point out my mistake?
i’ve tried chatgpt and console log but none of these helps. I am new in website development so please forgive me if my issue is silly.
von is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.