-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (48 loc) · 1.53 KB
/
Copy pathscript.js
File metadata and controls
92 lines (48 loc) · 1.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Warm Background Toggle with smooth animation
function changeBackground() {
document.body.classList.toggle("warm");
}
// API Integration
async function loadUsers() {
const list = document.getElementById("userList");
list.innerHTML = "<li>Loading users...</li>";
try {
const response = await fetch("https://jsonplaceholder.typicode.com/users");
if (!response.ok) {
throw new Error("API response failed");
}
const data = await response.json();
list.innerHTML = "";
data.forEach(user => {
const li = document.createElement("li");
li.textContent = `${user.name} (${user.email})`;
list.appendChild(li);
});
}
catch (error) {
list.innerHTML = "<li style='color:red;'>Failed to load users. Check Live Server.</li>";
console.error(error);
}
}
// Form Validation + Refresh
function validateForm() {
var name =
document.getElementById("name").value.trim();
var email =
document.getElementById("email").value.trim();
var message =
document.getElementById("message");
if (name === "" || email === "") {
message.style.color = "red";
message.textContent =
"Please fill all fields.";
return false;
}
message.style.color = "green";
message.textContent =
"Form submitted successfully! Refreshing...";
setTimeout(function () {
location.reload();
}, 1500);
return false;
}