script.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. window.onload = () =>{
  2. this.sessionStorage.setItem("username", "admin");
  3. this.sessionStorage.setItem("password", "qwerty");
  4. }
  5. var input = document.getElementsByTagName('input');
  6. var login = document.getElementById('log-in');
  7. var form = document.querySelector('form');
  8. form.onsubmit = ()=>{return false}
  9. login.onclick = ()=>{
  10. if ((input[0].value != "") && (input[1].value != ""))
  11. {
  12. if ((input[0].value == sessionStorage.getItem("username")) && (input[1].value == sessionStorage.getItem("password")))
  13. {
  14. form.onsubmit = ()=>{return 1}
  15. }
  16. else
  17. {
  18. if ((input[0].value != sessionStorage.getItem("username")))
  19. {
  20. input[0].nextElementSibling.textContent = "Имя не правильно";
  21. setTimeout(()=>{
  22. input[0].nextElementSibling.textContent = "";
  23. }, 2000);
  24. }
  25. if ((input[1].value != sessionStorage.getItem("password")))
  26. {
  27. input[1].nextElementSibling.textContent = "Пароль не правильно";
  28. setTimeout(()=>{
  29. input[1].nextElementSibling.textContent = "";
  30. }, 2000);
  31. }
  32. }
  33. }
  34. else
  35. {
  36. if (input[0].value == "")
  37. {
  38. input[0].nextElementSibling.textContent = "Username is empty";
  39. setTimeout(()=>{
  40. input[0].nextElementSibling.textContent = "";
  41. }, 2000);
  42. }
  43. if (input[1].value == "")
  44. {
  45. input[1].nextElementSibling.textContent = "Password is empty";
  46. setTimeout(()=>{
  47. input[1].nextElementSibling.textContent = "";
  48. }, 2000);
  49. }
  50. }
  51. }