-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
54 lines (50 loc) · 2.03 KB
/
function.js
File metadata and controls
54 lines (50 loc) · 2.03 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
document.addEventListener('DOMContentLoaded', function () {
// Star rating system
document.querySelectorAll('.star').forEach(function(star) {
star.addEventListener('click', function() {
let value = this.getAttribute('data-value');
let parent = this.closest('.criteria-item');
parent.querySelectorAll('.star').forEach(function(star) {
star.classList.remove('selected');
});
for (let i = 0; i < value; i++) {
parent.querySelectorAll('.star')[i].classList.add('selected');
}
parent.querySelector('input[type="hidden"]').value = value;
});
});
// Meeting and Connecting buttons
document.querySelectorAll('.yes, .no').forEach(function(button) {
button.addEventListener('click', function() {
let value = this.getAttribute('data-value');
let parent = this.closest('.col-md-6');
parent.querySelectorAll('.btn').forEach(function(btn) {
btn.classList.remove('active');
});
this.classList.add('active');
parent.querySelector('input[type="hidden"]').value = value;
});
});
// Form submission handler
document.querySelector('#ratingForm').addEventListener('submit', function(event) {
event.preventDefault();
const form = event.target;
fetch(form.action, {
method: form.method,
body: new FormData(form),
})
.then(response => response.json())
.then(result => {
if (result.success) {
alert('Ratings submitted successfully!');
// Optionally reset the form or update the UI
} else {
alert('Error submitting the ratings: ' + result.message);
}
})
.catch(error => {
console.error('Error submitting ratings:', error);
alert('Error submitting the ratings.');
});
});
});