forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedback.js
71 lines (59 loc) · 1.88 KB
/
feedback.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
69
70
71
document.addEventListener('DOMContentLoaded', () => {
const starsContainers = document.getElementsByClassName("stars");
const ratingTexts = document.querySelectorAll('[id$="-rating-text"]');
let currentRating = 0;
function colourStar(ind , container) {
let s = container.querySelectorAll("span");
s = Array.from(s);
// remove existing rating
for(let i = 0; i < s.length; i++) {
s[i].style.color = "white";
}
for(let i = 0; i < ind; i++) {
s[i].style.color = "#FFA500";
}
// console.log(container);
}
// Create 5 stars dynamically for each stars container
Array.from(starsContainers).forEach((starsContainer, index) => {
for (let i = 1; i <= 5; i++) {
const star = document.createElement('span');
star.classList.add('star');
star.innerHTML = '★';
star.setAttribute('data-rating', i);
starsContainer.appendChild(star);
star.addEventListener('click', () => {
currentRating = i;
updateRating(index);
colourStar(i , starsContainer);
});
}
});
const updateRating = (index) => {
ratingTexts[index].textContent = `Rating: ${currentRating}`;
};
});
function submitFeedback() {
var feedbackInput = document.getElementById("feedback-input");
var feedback = feedbackInput.value.trim();
// Check if the feedback is empty
if (feedback === "") {
// Show a SweetAlert error modal
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Please enter your feedback before submitting.',
});
return; // Exit the function if feedback is empty
}
Swal.fire({
icon: 'success',
title: 'Success!',
text: 'Your response has been recorded.',
}).then((result) => {
// Clear the feedback input box after the user acknowledges the success modal
if (result.isConfirmed || result.isDismissed) {
feedbackInput.value = "";
}
});
}