-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript2.js
109 lines (102 loc) · 3.16 KB
/
script2.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Validar formulario
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("datos").addEventListener('submit', validarFormulario);
});
function validarFormulario(evento) {
evento.preventDefault();
let nombre = document.getElementById('nombre').value;
if(nombre.length > 50) {
Swal.fire({
title: 'Error en el nombre',
text: 'máximo de 50 caracteres',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
} else if (nombre == ""){
Swal.fire({
title: 'Error en el nombre',
text: 'debes escribir un nombre',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}
let email = document.getElementById("email").value;
if(email.indexOf("@")==-1 || email.indexOf(".")==-1){
Swal.fire({
title: 'Error en el email',
text: 'El E-mail es invalido, sugerencia: xxxxx@xxxxx.xxx',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
} else if (email=""){
Swal.fire({
title: 'Error en el email',
text: 'debes escribir un correo',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}
let telefono = document.getElementById("telefono").value;
if (telefono ==""){
Swal.fire({
title: 'Error en el asunto',
text: 'Debes escribir un telefono',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}
let asunto = document.getElementById("asunto").value;
if(asunto.length > 50) {
Swal.fire({
title: 'Error en el asunto',
text: 'Puede contener un máximo de 50 caracteres',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}else if(asunto==""){
Swal.fire({
title: 'Error en el asunto',
text: 'Debes escribir un asunto',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}
let mensaje = document.getElementById("mensaje").value;
if(mensaje.length > 500) {
Swal.fire({
title: 'Error en el mensaje',
text: 'Puede contener un máximo de 500 caracteres',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}else if(mensaje==""){
Swal.fire({
title: 'Error en el mensaje',
text: 'Debes escribir un mensaje',
icon: 'error',
confirmButtonText: 'Continuar'
})
return;
}
this.submit();
}
var btnEnviar = document.getElementById('enviar');
btnEnviar.onclick = enviar;
function enviar (validarFormulario){
console.log('aaah')
Swal.fire({
position: 'center',
icon: 'success',
title: 'Mensaje enviado, me contactaré contigo pronto!',
showConfirmButton: false,
timer: 1500
})
}