MediaWiki:Common.js: различия между версиями

Материал из ЮУГМУ Вики
(Полностью удалено содержимое страницы)
Метка: очистка
Нет описания правки
Строка 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';
    }
  });
});

Версия от 11:25, 17 мая 2024

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