-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
27 lines (27 loc) · 819 Bytes
/
index.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
<html>
<head>
<title>Exemplo</title>
</head>
<body>
<form id="form">
<input id="name" type="text" placeholder="Nome" required/>
<input id="lastname" type="text" placeholder="Sobrenome" required/>
<input name="submit" type="submit" value="Enviar" />
</form>
</body>
<script type="text/javascript">
var elements = document.getElementsByTagName("INPUT");
for (var i = 0; i < elements.length; i++) {
elements[i].oninvalid = function(e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity("Preencha o campo "+e.target.placeholder);
//customize sua mensagem acima
}
};
elements[i].oninput = function(e) {
e.target.setCustomValidity("");
};
}
</script>
</html>