-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (60 loc) · 2.47 KB
/
script.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Requisito 3 - Validação de login
const emailInput = document.getElementById('email-input');
const passwordInput = document.getElementById('password-input');
const loginButton = document.getElementById('login-button');
loginButton.addEventListener('click', () => (emailInput.value === 'tryber@teste.com'
&& passwordInput.value === '123456' ? alert('Olá, Tryber!') : alert('Email ou senha inválidos.')));
// Requisito 18 - Consentimento obrigatório
const agreementBox = document.getElementById('agreement');
const submitButton = document.getElementById('submit-btn');
agreementBox.addEventListener('click', () => {
if (agreementBox.checked) {
submitButton.disabled = false;
} else {
submitButton.disabled = true;
}
});
// Requisito 20 - Contador de caracteres
const textArea = document.getElementById('textarea');
const textAreaCounter = document.getElementById('counter');
textArea.addEventListener('keyup', () => {
const length = textArea.textLength;
const maxLength = 500;
const counter = maxLength - length;
textAreaCounter.innerText = counter;
});
// Requisito 21 - Imprimir formulário
const forms = document.getElementById('evaluation-form');
const firstName = document.getElementById('input-name');
const lastName = document.getElementById('input-lastname');
const email = document.getElementById('input-email');
const house = document.getElementById('house');
function makeParagraph(key, value) {
const p = document.createElement('p');
p.innerText = `${key}: ${value}`;
forms.appendChild(p);
}
/** Source: https://pt.stackoverflow.com/questions/82968/pegar-valor-de-um-button-radio */
function printSummary() {
const fullName = `${firstName.value} ${lastName.value}`;
const family = document.querySelector('input[name=family]:checked');
const rate = document.querySelector('input[name=rate]:checked');
const subjects = document.querySelectorAll('inpit[class=subject]');
const selectedSubjects = [];
for (let i = 0; i < subjects.length; i += 1) {
selectedSubjects.push(subjects[i].value);
}
forms.innerHTML = '';
makeParagraph('Nome', fullName);
makeParagraph('Email', email.value);
makeParagraph('Casa', house.value);
makeParagraph('Família', family.value);
makeParagraph('Matérias', `${selectedSubjects.join(', ')}`);
makeParagraph('Avaliação', rate.value);
makeParagraph('Observações', textArea.value);
}
submitButton.addEventListener('click', (event) => {
const submit = event;
submit.preventDefault();
printSummary();
});