-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (53 loc) · 2.12 KB
/
script.js
File metadata and controls
62 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// script.js
// ------------------- Signup Form Validation -------------------
const signupForm = document.querySelector('form[action="signup.php"]');
if (signupForm) {
signupForm.addEventListener('submit', function (e) {
const name = signupForm.querySelector('input[name="name"]').value.trim();
const mobile = signupForm.querySelector('input[name="mobile"]').value.trim();
const mpin = signupForm.querySelector('input[name="mpin"]').value.trim();
// Simple validation
if (name === '' || mobile === '' || mpin === '') {
alert('Please fill all fields');
e.preventDefault(); // Stop form submission
return;
}
if (mpin.length < 4) {
alert('Password must be at least 4 characters');
e.preventDefault();
return;
}
});
}
// ------------------- Login Form Validation -------------------
const loginForm = document.querySelector('form[action="login.php"]');
if (loginForm) {
loginForm.addEventListener('submit', function (e) {
const userId = loginForm.querySelector('input[name="userId"]').value.trim();
const password = loginForm.querySelector('input[name="password"]').value.trim();
if (userId === '' || password === '') {
alert('Please fill all fields');
e.preventDefault();
return;
}
});
}
// ------------------- Toggle Password Visibility -------------------
const passwordFields = document.querySelectorAll('input[type="password"]');
passwordFields.forEach(field => {
const toggleBtn = document.createElement('span');
toggleBtn.style.cursor = 'pointer';
toggleBtn.style.marginLeft = '5px';
field.parentNode.insertBefore(toggleBtn, field.nextSibling);
toggleBtn.addEventListener('click', () => {
field.type = field.type === 'password' ? 'text' : 'password';
});
});
// ------------------- Hamburger Menu Toggle (if any) -------------------
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('navLinks');
if (hamburger && navLinks) {
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
}