589
правок
User (обсуждение | вклад) (Полностью удалено содержимое страницы) Метка: очистка |
User (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
if (document.readyState !== 'loading') { | |||
formCreateSelect(); | |||
} else { | |||
document.addEventListener('DOMContentLoaded', function () { | |||
formCreateSelect(); | |||
}); | |||
} | |||
function formCreateSelect() { | |||
} | |||
// Get the select element and the forms | |||
const select = document.getElementById('select'); | |||
const forms = document.querySelectorAll('.createbox'); | |||
// Create the select options | |||
const options = [ | |||
{ value: 'Личность:', text: 'Статья про личность...' }, | |||
{ value: 'Подразделение:', text: 'Статья про подразделение...' } | |||
]; | |||
options.forEach((option) => { | |||
const opt = document.createElement('option'); | |||
opt.value = option.value; | |||
opt.text = option.text; | |||
select.appendChild(opt); | |||
}); | |||
// Add event listener to the select element | |||
select.addEventListener('change', (e) => { | |||
const value = e.target.value; | |||
forms.forEach((form) => { | |||
const prefixInput = form.querySelector('input[name="prefix"]'); | |||
if (prefixInput) { | |||
prefixInput.value = value; | |||
} | |||
}); | |||
// Hide all forms except the one that matches the selected value | |||
forms.forEach((form) => { | |||
const prefixInput = form.querySelector('input[name="prefix"]'); | |||
if (prefixInput && prefixInput.value === value) { | |||
form.style.display = 'block'; | |||
} else { | |||
form.style.display = 'none'; | |||
} | |||
}); | |||
}); | |||