forked from brunorg/AmorimVs2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formulario.html
49 lines (45 loc) · 1.39 KB
/
formulario.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
<html>
<head>
<title>Como Validar um Formulário dinamicamente com jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
$("input").blur(function(){
if($(this).val() == "")
{
$(this).css({"border" : "1px solid #F00", "padding": "2px"});
}
});
$("#botao").click(function(){
var cont = 0;
$("#form input").each(function(){
if($(this).val() == "")
{
$(this).css({"border" : "1px solid #F00", "padding": "2px"});
cont++;
}
});
if(cont == 0)
{
$("#form").submit();
}
});
});
</script>
</head>
<body>
<form id="form" name="form" method="post">
<span style="display:inline-table; width:70px;">Nome:</span>
<input type="text" id="nome" value="" />
<br /><br />
<span style="display:inline-table; width:70px;">Email:</span>
<input type="text" id="email" value="" />
<br /><br />
<span style="display:inline-table; width:70px;">Telefone:</span>
<input type="text" id="telefone" value="" />
<br /><br />
<input type="button" id="botao" value="enviar" />
</form>
</body>
</html>
Read more: http://www.linhadecodigo.com.br/artigo/3592/jquery-criando-uma-validacao-de-formularios-html.aspx#ixzz3O4q2lVkZ