-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (47 loc) · 1.62 KB
/
index.js
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
window.onload = function() {
alert("Welcome to our website!");
};
function slide() {
var box = document.getElementById('box');
var currentPosition = box.getBoundingClientRect().left;
var targetPosition = 300; // Target position for sliding (adjust as needed)
var distance = targetPosition - currentPosition;
box.style.left = distance + 'px';
}
function validateForm() {
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var nameError = document.getElementById('nameError');
var emailError = document.getElementById('emailError');
var passwordError = document.getElementById('passwordError');
var isValid = true;
// Validate name
if (name === "") {
nameError.textContent = "Name is required";
isValid = false;
} else {
nameError.textContent = "";
}
// Validate email
if (email === "") {
emailError.textContent = "Email is required";
isValid = false;
} else if (!/\S+@\S+\.\S+/.test(email)) {
emailError.textContent = "Invalid email address";
isValid = false;
} else {
emailError.textContent = "";
}
// Validate password
if (password === "") {
passwordError.textContent = "Password is required";
isValid = false;
} else if (password.length < 8) {
passwordError.textContent = "Password must be at least 8 characters long";
isValid = false;
} else {
passwordError.textContent = "";
}
return isValid;
}