mirror of
https://github.com/Matewoo/tablet-web-survey.git
synced 2026-11-18 13:52:47 +01:00
new submit logic
There's no submit button anymore. Clicking on an emoji submits the results automatically
This commit is contained in:
+31
-1
@@ -1,4 +1,4 @@
|
|||||||
document.querySelectorAll('.emoji').forEach(button => {
|
/* document.querySelectorAll('.emoji').forEach(button => {
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
const category = button.getAttribute('data-category');
|
const category = button.getAttribute('data-category');
|
||||||
if (category === 'Fleischgericht' || category === 'Vegetarisch' || category === 'Tagesgericht' || category === 'Tagessalat') {
|
if (category === 'Fleischgericht' || category === 'Vegetarisch' || category === 'Tagesgericht' || category === 'Tagessalat') {
|
||||||
@@ -44,4 +44,34 @@ document.getElementById('submit').addEventListener('click', () => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
submitButton.disabled = false;
|
submitButton.disabled = false;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
}); */
|
||||||
|
|
||||||
|
document.querySelectorAll('.emoji').forEach(button => {
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
const category = button.getAttribute('data-category');
|
||||||
|
const results = {};
|
||||||
|
results[category] = button.id;
|
||||||
|
|
||||||
|
fetch('/submit', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(results)
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log('Success:', data);
|
||||||
|
document.getElementById('thank-you-message').style.display = 'block';
|
||||||
|
document.getElementById('content').style.visibility = 'hidden';
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('thank-you-message').style.display = 'none';
|
||||||
|
document.getElementById('content').style.visibility = 'visible';
|
||||||
|
document.querySelectorAll('.emoji').forEach(button => button.classList.remove('selected'));
|
||||||
|
}, 1000);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user