index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. document.addEventListener("DOMContentLoaded", () => {
  3. const form = document.querySelector('.js-form');
  4. const formLogin = document.querySelector('.js-form-login');
  5. const formPassword = document.querySelector('.js-form-password');
  6. const formAlerts = document.querySelectorAll('.js-alert');
  7. const formAlertSuccess = document.querySelector('.js-alert-success');
  8. const formAlertDanger = document.querySelector('.js-alert-danger');
  9. // authorization credentials
  10. const credentials = {
  11. login: 'admin',
  12. password: 'qwerty',
  13. };
  14. const alertsVisibility = formType => {
  15. Array.from(formAlerts).forEach(element => {
  16. element.style.setProperty('display', 'none');
  17. });
  18. formType.style.setProperty('display', 'block');
  19. }
  20. form.addEventListener('submit', (event) => {
  21. event.preventDefault();
  22. if(formLogin.value === credentials.login && formPassword.value === credentials.password) {
  23. alertsVisibility(formAlertSuccess);
  24. } else {
  25. alertsVisibility(formAlertDanger);
  26. }
  27. })
  28. });