This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedback.js
55 lines (46 loc) · 1.51 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
document.addEventListener('DOMContentLoaded', () => {
const starsContainers = document.getElementsByClassName("stars");
const ratingTexts = document.querySelectorAll('[id$="-rating-text"]');
let currentRating = 0;
// 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);
star.addEventListener('click', () => {
currentRating = i;
updateRating(index);
});
starsContainer.appendChild(star);
}
});
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 = "";
}
});
}