-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathe116_formas_html5.html
122 lines (96 loc) · 2.39 KB
/
e116_formas_html5.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>formas html5</title>
<style type="text/css">
div {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
border-style: solid;
padding: 80px;
width: 700px;
}
form {
border-style: solid;
border-color: blue;
padding: 20px;
}
label {
width: 250px;
display: inline-block;
text-align: right;
}
input {
width: 200px;
}
.boton {
text-align: center;
}
/* --- DEFINIMOS LOS ESTILOS PARA LOS INPUTS CUANDO ESTOS SON VALIDOS Y NO VALIDOS*/
input:required:invalid, input:focus:invalid {
background-image: url(imagenes/invalido.png);
background-position: right top;
background-repeat: no-repeat;
}
input:required:valid {
background-image: url(imagenes/valido.png);
background-position: right top;
background-repeat: no-repeat;
}
</style>
<script>
window.onload = function() {
var elEmail = document.querySelector("#email");
//mostramos como cambiar el mensaje de error para el campo email
elEmail.addEventListener("invalid", function() {
//este evento solo puede ocurrir al hacer el submit
if (elEmail.validity.valid === false) {
elEmail.setCustomValidity("Debes introducir un email en formato correcto");
}
});
}
</script>
</head>
<body>
<div >
<form method="get" action="ajax/procesa.php">
<p>
<label>Campo obligatorio(required):</label>
<input type="text" name="name" required>
</p>
<p>
<label>email(required):</label>
<input id="email" type="email" name="email" required placeholder="Introduce email">
</p>
<p>
<label>url:</label>
<input type="url" name="website" >
</p>
<p>
<label>url(expresion regular):</label>
<input type="url" name="website" required pattern="https?://[a-z]+.+com">
</p>
<p>
<label>edad(number):</label>
<input type="number" name="edad" min="18" max="99" value="21">
<br>
</p>
<p>
<label>edad(number):</label>
<input type="number" name="edad" min="18" max="99" value="21">
<br>
</p>
<p>
<label>edad(number):</label>
<input type="number" name="edad" min="18" max="99" value="21">
<br>
</p>
<p class="boton">
<input type="submit" value="Enviar(ejemplo submit)">
</p>
</form>
</div>
</body>
</html>