You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.4 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function () {
const addButtons = document.querySelectorAll('.addServiceButton');
addButtons.forEach(function (button) {
button.addEventListener('click', function () {
const serviceId = button.getAttribute('data-service-id');
const serviceTitle = button.getAttribute('data-service-title');
const selectTag = document.getElementById('servicesSelectTag');
const option = document.createElement('option');
option.value = serviceId;
option.text = serviceTitle;
if (button.classList.contains('added')) {
button.classList.remove('added');
button.classList.remove('bg-red-500');
button.classList.add('bg-osiblue');
button.querySelector('p').textContent = "Add";
const optionToRemove = selectTag.querySelector(`option[value="${serviceId}"]`);
if (optionToRemove) {
selectTag.removeChild(optionToRemove);
}
} else {
button.classList.add('added');
button.classList.add('bg-red-500');
button.querySelector('p').textContent = "Remove";
selectTag.appendChild(option);
option.selected = true;
}
});
});
});