Skip to content

Commit 4de8c18

Browse files
creating a popup page inside it
1 parent 8b9f310 commit 4de8c18

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

profile.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const profileUsername = document.getElementById("profilename");
22
const profileEmail = document.getElementById("profileEmail");
33
const editProfileButton = document.getElementById("editProfileButton");
4+
const popup = document.getElementById("popup");
5+
const overlay = document.getElementById("overlay");
6+
const saveButton = document.getElementById("saveButton");
7+
const cancelButton = document.getElementById("cancelButton");
8+
const newNameInput = document.getElementById("newName");
9+
const newEmailInput = document.getElementById("newEmail");
410
const loggedinUser = JSON.parse(localStorage.getItem("loggedinUser"));
511

612
if (!loggedinUser) {
@@ -11,17 +17,38 @@ if (!loggedinUser) {
1117
}
1218

1319
editProfileButton.addEventListener("click", () => {
14-
const newName = prompt("Enter your new Name:", loggedinUser.name);
15-
const newEmail = prompt("Enter your new email:", loggedinUser.email);
20+
newNameInput.value = loggedinUser.name;
21+
newEmailInput.value = loggedinUser.email;
22+
popup.classList.add("active");
23+
overlay.classList.add("active");
24+
});
25+
26+
cancelButton.addEventListener("click", () => {
27+
popup.classList.remove("active");
28+
overlay.classList.remove("active");
29+
});
30+
31+
saveButton.addEventListener("click", () => {
32+
const newName = newNameInput.value.trim();
33+
const newEmail = newEmailInput.value.trim();
1634

1735
if (newName && newEmail) {
1836
loggedinUser.name = newName;
1937
loggedinUser.email = newEmail;
2038
localStorage.setItem("loggedinUser", JSON.stringify(loggedinUser));
2139

40+
profileUsername.textContent = `Name: ${loggedinUser.name}`;
41+
profileEmail.textContent = `Email: ${loggedinUser.email}`;
42+
2243
alert("Profile updated successfully!");
23-
window.location.href = "landing.html";
44+
popup.classList.remove("active");
45+
overlay.classList.remove("active");
2446
} else {
2547
alert("Please fill in all fields.");
2648
}
2749
});
50+
51+
overlay.addEventListener("click", () => {
52+
popup.classList.remove("active");
53+
overlay.classList.remove("active");
54+
});

0 commit comments

Comments
 (0)