Open rosa33783 opened 1 year ago
const checkboxes = document.querySelectorAll('.heart-checkbox'); const listLiked = document.querySelector('.listLiked'); const list = document.querySelector('.list');
checkboxes.forEach(checkbox => { checkbox.addEventListener('change', function() { if (this.checked) { const label = this.nextElementSibling; listLiked.appendChild(this); listLiked.appendChild(label); } else { const label = this.nextElementSibling; const index = Array.from(listLiked.children).indexOf(label); if (index !== -1) { listLiked.removeChild(label); listLiked.removeChild(this); list.insertBefore(this, list.children[index]); list.insertBefore(label, list.children[index]); } } }); });
checkboxes.forEach(checkbox => { checkbox.addEventListener('change', function() { const checkboxValue = this.checked;
// Send an HTTP request to the server with the checkbox state
fetch('/updateCheckboxState', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ state: checkboxValue })
})
.then(response => {
if (response.ok) {
console.log('Checkbox state successfully sent to the server.');
} else {
console.error('Failed to send checkbox state to the server.');
}
})
.catch(error => {
console.error('An error occurred while sending checkbox state:', error);
});
}); });
Heb je nog problemen?
Kan deze gesloten worden @rosa33783 ?
code in mijn index.js
const checkboxes = document.querySelectorAll('.heart-checkbox');
checkboxes.forEach(checkbox => { checkbox.addEventListener('change', function() { const checkboxValue = this.checked;
}); });
like.handlebars
Liked chats