<select></select>
<output></output>
const options = {
'осень': new Date(2022, 8, 1),
'новый год': new Date(2023, 0, 1),
'налоги': new Date(2023, 3, 1),
};
const select = document.querySelector('select');
const output = document.querySelector('output');
Object.keys(options).forEach(title => {
const el = document.createElement('option');
el.innerText = title;
el.value = title;
select.appendChild(el);
});
let current = select.value;
select.addEventListener('change', () => {
current = select.value;
update();
});
const update = () => {
let s = Math.floor((options[current] - new Date())/1e3);
output.innerText = s;
};
setInterval(update, 250);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.