-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (29 loc) · 1018 Bytes
/
script.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
// Function to change background color
function changeBackgroundColor() {
document.body.style.backgroundColor = "lightblue";
}
// Event listener for button click to change background color
document
.getElementById("changeColorBtn")
.addEventListener("click", changeBackgroundColor);
// Form validation
document
.getElementById("submitBtn")
.addEventListener("click", function (event) {
event.preventDefault(); // Prevent form submission
var nameInput = document.getElementById("name");
var emailInput = document.getElementById("email");
if (nameInput.value.trim() === "" || emailInput.value.trim() === "") {
alert("Please fill in all required fields.");
} else {
alert("Form submitted successfully!");
}
});
// Image hover effect
var image = document.getElementById("image");
image.addEventListener("mouseover", function () {
image.src = "/assets/female-avatar.jpg";
});
image.addEventListener("mouseout", function () {
image.src = "/assets/male-avatar.jpg";
});