-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTExt.php
More file actions
59 lines (59 loc) · 1.62 KB
/
TExt.php
File metadata and controls
59 lines (59 loc) · 1.62 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
<html>
<head>
<title> Teste de validação de formulário em javascript </title>
<script language="javascript">
//Aqui todo o código javascript
//Função que verificará se nossos campos com preenchimento obrigatório estão mesmo preenchidos
//Caso não estejam, um alert será exibido
function verifica(){
if(document.form1.nome.value==""){
alert("Erro! O Campo \"Nome\" está em branco!");
document.form1.nome.focus();
return false;
}
if(document.form1.sobrenome.value==""){
alert("Erro! O Campo \"Sobrenome\" está em branco!");
document.form1.sobrenome.focus();
return false;
}
//Verificando se a combo do estado tem valor selecionado
if(document.form1.estado.value==""){
alert("Erro! Você precisa selecionar um estado!");
document.form1.estado.focus();
return false;
}
return true;
}
//Função check analiza a função verifica e envia o formulário ou para o processo
function check(){
if(verifica())
document.form1.submit();
}
//função teclaPress valida os campos caso o usuário
//Precione enter em um dos dois edits em vez de clicar no botão
function teclaPress(){
var tecla=event.keyCode;
if(tecla==13){
if(verifica())
return true;
else
return false
}
else
return tecla;
}
</script>
</head>
<body>
<form name="form1" action="arquivo.php">
Nome: <input type="text" name="nome" value="" onKeyPress="return teclaPress()"><br>
Sobrenome: <input type="text" name="sobrenome" value="" onKeyPress="return teclaPress();">
Estado: <select name="estado">
<option value="" selected> Selecione
<option value="SP"> São Paulo
<option name="RJ"> Rio de Janeiro
</select>
<input type="button" value="Enviar" OnClick="check();">
</form>
</body>
</html>