-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
final.js
52 lines (42 loc) · 1.87 KB
/
final.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
document.getElementById("editButton").addEventListener("click", function () {
// Hide the display section
document.getElementById("profileDisplay").style.display = "none";
// Show the edit form
document.getElementById("profileEdit").style.display = "block";
});
document
.getElementById("profileForm")
.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent form submission
// Get updated values
const updatedUsername = document.getElementById("username").value;
const updatedEmail = document.getElementById("email").value;
const updatedBio = document.getElementById("bio").value;
// Update the displayed values
document.getElementById("displayUsername").textContent = updatedUsername;
document.getElementById("displayEmail").textContent = updatedEmail;
document.getElementById("displayBio").textContent = updatedBio;
// Hide the edit form and show the display section again
document.getElementById("profileEdit").style.display = "none";
document.getElementById("profileDisplay").style.display = "flex"; // Show as flex for alignment
alert("Profile updated successfully!");
});
// Handle cancel button
document.getElementById("cancelButton").addEventListener("click", function () {
// Hide the edit form and show the display section again
document.getElementById("profileEdit").style.display = "none";
document.getElementById("profileDisplay").style.display = "flex"; // Show as flex for alignment
});
// Handle image upload
document
.getElementById("imageUpload")
.addEventListener("change", function (event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function (e) {
document.getElementById("profileImage").src = e.target.result; // Update the image src to the new file
};
if (file) {
reader.readAsDataURL(file);
}
});