0% found this document useful (0 votes)
2 views

Script.js

The document contains JavaScript code that handles the submission of a login form. It includes basic validation for username and password, simulates a successful login, and implements a 'remember me' feature using local storage. Additionally, it checks for a remembered user when the page loads and populates the username field if applicable.

Uploaded by

f78jyvwgcd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Script.js

The document contains JavaScript code that handles the submission of a login form. It includes basic validation for username and password, simulates a successful login, and implements a 'remember me' feature using local storage. Additionally, it checks for a remembered user when the page loads and populates the username field if applicable.

Uploaded by

f78jyvwgcd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

document.getElementById('loginForm').

addEventListener('submit', function(e) {
e.preventDefault();

const username = document.getElementById('username').value;


const password = document.getElementById('password').value;
const rememberMe = document.querySelector('input[name="remember"]').checked;

// Basic validation
if (!username || !password) {
alert('Please fill in all fields');
return;
}

// Add your login logic here


console.log('Login attempted with:', { username, password, rememberMe });

// Simulate successful login


alert('Login successful! (This is a demo)');

// Clear form fields


this.reset();

// Remember me functionality
if (rememberMe) {
localStorage.setItem('rememberedUser', username);
} else {
localStorage.removeItem('rememberedUser');
}
});

// Check for remembered user


window.addEventListener('DOMContentLoaded', () => {
const rememberedUser = localStorage.getItem('rememberedUser');
if (rememberedUser) {
document.getElementById('username').value = rememberedUser;
document.querySelector('input[name="remember"]').checked = true;
}
});

You might also like