Sensinki / Blok-Tech-Team-4A

MIT License
1 stars 0 forks source link

database code #4

Open rosa33783 opened 1 year ago

rosa33783 commented 1 year ago

code in mijn index.js

const checkboxes = document.querySelectorAll('.heart-checkbox');

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);
});

}); });

like.handlebars

Liked chats

<section class="listLiked"> 

</section>

<section class="list">
    <input type="checkbox" id="Valorant" class="heart-checkbox">
    <label for="Valorant" class="heart-label">Valorant</label>

    <input type="checkbox" id="Minecraft" class="heart-checkbox">
    <label for="Minecraft" class="heart-label">Minecraft</label>

    <input type="checkbox" id="MarioBros" class="heart-checkbox">
    <label for="MarioBros" class="heart-label">Mario Bros</label>

    <input type="checkbox" id="LeagueOfLegends" class="heart-checkbox">
    <label for="LeagueOfLegends" class="heart-label">League of Legends</label>

    <input type="checkbox" id="CallOfDuty" class="heart-checkbox">
    <label for="CallOfDuty" class="heart-label">Call of Duty</label>

    <input type="checkbox" id="PUBG" class="heart-checkbox">
    <label for="PUBG" class="heart-label">PlayerUnknown's Battlegrounds</label>

    <input type="checkbox" id="Overwatch2" class="heart-checkbox">
    <label for="Overwatch2" class="heart-label">Overwatch 2</label>

    <input type="checkbox" id="CSGO" class="heart-checkbox">
    <label for="CSGO" class="heart-label">CSGO</label>

    <input type="checkbox" id="Roblox" class="heart-checkbox">
    <label for="Roblox" class="heart-label">Roblox</label>

    <input type="checkbox" id="RocketLeague" class="heart-checkbox">
    <label for="RocketLeague" class="heart-label">Rocket League</label>
</section>

rosa33783 commented 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);
});

}); });

D0nnaz commented 1 year ago

Heb je nog problemen?

D0nnaz commented 1 year ago

Kan deze gesloten worden @rosa33783 ?