-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (68 loc) · 2.25 KB
/
script.js
File metadata and controls
76 lines (68 loc) · 2.25 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const sectionRight = document.querySelector('.right-content');
const validateCamps = document.querySelectorAll('.cadastro input');
const getGender = document.querySelectorAll('.radioButtons input');
const getOpt = document.getElementsByTagName('select');
function alertLogin() {
const buttonLogin = document.getElementById('button-login');
const inputLogin = document.getElementById('user-email-phone');
buttonLogin.addEventListener('click', function () {
const loginValue = inputLogin.value;
alert(loginValue);
});
}
function registerValidate() {
for (let index = 0; index < 5; index += 1) {
if (validateCamps[index].value === '') {
const div = document.createElement('div');
div.innerHTML = `${validateCamps[index].name}: Campos inválidos`;
document.getElementById('cadastro').appendChild(div);
}
}
}
function createGenderRegister() {
let gender1 = '';
let gender2 = '';
for (let index = 0; index < 3; index += 1) {
if (getGender[index].checked === true) {
gender1 = `genero: ${getGender[index].value}`;
}
}
if (getGender[2].checked === true) {
const customGender = document.getElementById('genderText');
gender2 = ` > ${customGender.value}`;
}
return gender1 + gender2;
}
function setValueOnSectionRight() {
sectionRight.innerText = `Olá, ${validateCamps[0].value} ${validateCamps[1].value},
contato: ${validateCamps[2].value},
nascido em: ${getOpt[0].value}/${getOpt[1].value}/${getOpt[2].value}
e de ${createGenderRegister()};
Seus dados foram cadastrados com sucesso!`;
}
function checkValidRegister() {
const checkDivLenght = document.querySelectorAll('form div');
if (checkDivLenght.length === 0) {
setValueOnSectionRight();
}
}
function cleanDivs() {
const formDiv = document.querySelectorAll('.cadastro div');
for (let index = 0; index < formDiv.length; index += 1) {
if (formDiv[index].value !== '') {
document.querySelector('form div').remove();
}
}
}
function listeners() {
const registerButton = document.getElementById('facebook-register');
registerButton.addEventListener('click', function (event) {
event.preventDefault();
cleanDivs();
registerValidate();
checkValidRegister();
});
}
window.onload = function () {
listeners();
};