-
Notifications
You must be signed in to change notification settings - Fork 0
/
cadastroclientes.html
89 lines (79 loc) · 2.61 KB
/
cadastroclientes.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container{
width: 400px;
margin: auto;
padding: 5px;
}
input{
width: 100%;
}
</style>
</head>
<body>
<h1>Cadastro de Clientes</h1>
<hr>
<div class="container">
<label for="nome">Nome</label>
<input type="text" id="nome" placeholder="Informe o nome" />
<label for="email">Email</label>
<input type="email" id="email" placeholder="Informe o email" />
<label for="email">Fone</label>
<input type="text" id="fone" placeholder="Informe o telefone" />
<div>
<button onclick="salvar(limpar)">Salvar</button>
<button>Cancelar</button>
</div>
</div>
<script>
function salvar(callback){
const cliente = {
nome: "",
email: "",
fone: ""
}
cliente.nome = document.getElementById("nome").value
cliente.email = document.getElementById("email").value
cliente.fone = document.getElementById("fone").value
if(cliente.nome == ""){
alert("insira um nome!")
document.getElementById("nome").focus()
return
}else{
cliente.nome = document.getElementById("nome").value
}if(cliente.email == ""){
alert("insira um email!")
document.getElementById("email").focus()
return
}else{
cliente.email = document.getElementById("email").value
}if(cliente.fone == ""){
alert("insira um telefone!")
document.getElementById("fone").focus()
return
}else{
cliente.fone = document.getElementById("fone").value
}
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(cliente)
}
fetch(" http://localhost:3000/clientes", options)
.then(data => data.json())
.then(cli => console.log(cli))
callback()
}
function limpar(){
document.getElementById("nome").value = ""
document.getElementById("email").value = ""
document.getElementById("fone").value = ""
}
</script>
</body>
</html>