const folder_selector = document.querySelectorAll('.pride_flags_user_settings .user-settings.folder-flavour select'); const button_selector = document.querySelectorAll('.pride_flags_user_settings .user-settings.button-flavour select'); const submit_button = document.querySelectorAll('.pride_flags_user_settings .settings-pride-submit'); fetch('/index.php/apps/pride_flags/settings') .then(res => JSON.parse(res)) .then(({folderPrideVariant, buttonPrideVariant}) => { folder_selector.value = folderPrideVariant; button_selector.value = buttonPrideVariant; }); function save() { const payload = { folderVariant: folder_selector.value, buttonVariant: button_selector.value, } fetch('index.php/apps/pride_flags/settings', { method: 'POST', body: JSON.stringify(payload), headers: { "Content-Type": "application/json", } }).then(response => { if (response.ok) { window.location.reload(); } }) } submit_button.on('click', e => save());