-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask8.html
More file actions
51 lines (46 loc) · 1.57 KB
/
task8.html
File metadata and controls
51 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
</head>
<body>
<form class="login-form">
<label>
Email
<input type="text" name="email" />
</label>
<label>
Password
<input type="password" name="password" />
</label>
<button type="submit">Log in</button>
</form>
<script>
// Отримання форми та елементів вводу
const form = document.querySelector('.login-form');
const emailInput = form.elements.email;
const passwordInput = form.elements.password;
// Обробник події submit
form.addEventListener('submit', function(event) {
event.preventDefault(); // Заборона стандартної поведінки відправки форми
// Перевірка на заповненість полів
if (emailInput.value.trim() === '' || passwordInput.value.trim() === '') {
alert('All form fields must be filled in');
} else {
// Створення об'єкту з введеними даними
const formData = {
email: emailInput.value.trim(),
password: passwordInput.value.trim()
};
// Виведення об'єкту в консоль
console.log(formData);
// Очищення значень полів та виведення повідомлення
form.reset();
alert('Form submitted successfully!');
}
});
</script>
</body>
</html>