-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 1.49 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
document.addEventListener("DOMContentLoaded", function () {
document
.getElementById("recommendation-form")
.addEventListener("submit", function (event) {
event.preventDefault();
let name = document.getElementById("name").value;
let message = document.getElementById("message").value;
// Create a new recommendation item
let recommendationItem = document.createElement("div");
recommendationItem.classList.add("recommendation-item");
// Create elements to display name and message
let nameLabel = document.createElement("p");
nameLabel.textContent = "Name: " + (name ? name : "Anonymous"); // If name is empty, display "Anonymous"
let messageLabel = document.createElement("p");
messageLabel.textContent = "Message: " + message;
// Append name and message elements to recommendation item
recommendationItem.appendChild(nameLabel);
recommendationItem.appendChild(messageLabel);
// Append recommendation item to the recommendation box
let recommendationBox = document.getElementById("recommendation-box");
recommendationBox.appendChild(recommendationItem);
// Optionally, you can clear the form fields after submission
document.getElementById("name").value = "";
document.getElementById("message").value = "";
window.alert("Thank you for submitting a recommendation!");
});
});