-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive-rating.js
71 lines (52 loc) · 1.95 KB
/
interactive-rating.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const userRatingForm = document.getElementById("ratingForm");
const userRate = document.getElementsByClassName("rate");
const parentUL = document.getElementById('rating-btns');
const btns = parentUL.getElementsByTagName('input');
let selectedValue = 0;
//a function to address the value being passed in the onclick
function pickRating(u){
selectedValue = u;
return selectedValue;
}
// handles assigning classes to the rating buttons
for (const btn of btns){
btn.addEventListener("click", function(){
if (this.classList.contains('inactive')){
this.classList.remove('inactive');
} else if (this.classList.contains('active')){
this.classList.remove('active');
this.classList.add('inactive');
} else {
this.classList.add('active');
}
});
}
userRatingForm.addEventListener("submit", (e) => {
e.preventDefault();
userRatingForm.remove();
thankyouPage();
});
// Thank You Page
function thankyouPage(){
const sect = document.querySelector('section');
const svgImg = document.createElement('img');
const newHead = document.createElement('h1');
if(sect.classList.contains('hidden')){
sect.classList.remove('hidden');
}
sect.appendChild(svgImg);
svgImg.src = "./images/illustration-thank-you.svg";
svgImg.setAttribute("class", "tySVG");
const message = document.createElement('p');
message.textContent = `You selected ${selectedValue} out of 5`;
sect.appendChild(message);
message.setAttribute("class", "tyResponse");
newHead.textContent = "Thank you!";
sect.appendChild(newHead);
newHead.setAttribute("class", "tyHead");
const newPara = document.createElement('p');
sect.appendChild(newPara);
newPara.textContent = `We appreciate you taking the time to give a rating. If you ever need more support,
don\'t hesitate to get in touch!`;
newPara.setAttribute("class", "tyPara");
}