-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (74 loc) · 2.76 KB
/
script.js
File metadata and controls
87 lines (74 loc) · 2.76 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
// Removing all content from rating box
function changeText() {
document.getElementById("flex-item1").innerHTML = "";
}
function addImage() {
// Creating new image content for the thank you page
const newImg = document.createElement("img");
newImg.setAttribute("src", "https://i.postimg.cc/tJxpfm28/Image-2-1.png");
newImg.setAttribute("alt", "Thank You Page Picture");
newImg.classList.add("thank-you-image");
// Displaying the content in "flex-item"
const newImageDisplay = document.getElementById("flex-item1");
newImageDisplay.appendChild(newImg);
}
function createInputDiv(selectedRating) {
// Creating Div element that displays vote input
const inputValueDiv = document.createElement("div");
inputValueDiv.classList.add("input-div");
// Adjusting inner text content in Div
inputValueDiv.innerText = `You selected ${selectedRating} out of 5`;
// Displaying the content in "flex-item"
const displayingInputDiv = document.getElementById("flex-item1");
displayingInputDiv.appendChild(inputValueDiv);
}
function createThankYouText() {
// Creating element
const thankYouText = document.createElement("div");
thankYouText.classList.add("thank-you-text");
// Changing inner text
thankYouText.innerText = "Thank You!";
// Displaying content
const displayingTYText = document.getElementById("flex-item1");
displayingTYText.appendChild(thankYouText);
}
function smallPara() {
// Creating Paragraph Div
const newPara = document.createElement("div");
newPara.classList.add("paraText");
// Adding inner text
newPara.innerText =
"We appreciate you taking the time to give a rating. If you ever need more support, don't hesitate to get in touch!";
// Displaying Div
const displayPara = document.getElementById("flex-item1");
displayPara.appendChild(newPara);
}
document.addEventListener("DOMContentLoaded", () => {
const button = document.getElementById("button1");
button.disabled = true; // Disable the submit button by default
button.addEventListener("click", () => {
const selectedRating = document
.querySelector(".selected")
?.getAttribute("data-rating");
changeText();
addImage();
createInputDiv(selectedRating);
createThankYouText();
smallPara();
});
// Get all rating choices
const ratingChoices = document.querySelectorAll(".crc");
// Adding an event listener to each rating choice
ratingChoices.forEach((choice) => {
choice.addEventListener("click", () => {
// Remove 'selected' class from all rating choices
ratingChoices.forEach((choice) => {
choice.classList.remove("selected");
});
// Add 'selected' class to clicked rating choice
choice.classList.add("selected");
// Enable the submit button
button.disabled = false;
});
});
});