-
Notifications
You must be signed in to change notification settings - Fork 0
/
alterarcadastro.html
76 lines (65 loc) · 2.25 KB
/
alterarcadastro.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Alterar dados</h1>
<hr>
<label>Digite um codigo de cliente</label>
<input type="number" id="idcliente" />
<button onclick="pesquisar()">Pesquisar</button>
<button onclick="excluir()">Excluir</button>
<hr>
<input id="nome" />
<input id="email" />
<input id="fone" />
<button onclick="alterar(limpar)">Gravar e alterar</button>
<script>
function pesquisar(){
var idpesquisa = document.getElementById("idcliente").value
fetch (`http://localhost:3000/clientes/${idpesquisa}`)
.then(data => data.json())
.then(result => mostrar(result))
function mostrar(result){
clientes = []
clientes = result
document.getElementById("nome").value = `${clientes.nome}`
document.getElementById("email").value = `${clientes.email}`
document.getElementById("fone").value = `${clientes.fone}`
}
}
function alterar(callback){
var idpesquisa = document.getElementById("idcliente").value
const clientes = {
nome: "",
email: "",
fone: ""
}
clientes.nome = document.getElementById("nome").value
clientes.email = document.getElementById("email").value
clientes.fone = document.getElementById("fone").value
const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(clientes)
}
fetch(`http://localhost:3000/clientes/${idpesquisa}` , options)
.then(data => data.json())
callback()
}
function limpar(){
document.getElementById("nome").value = ""
document.getElementById("email").value = ""
document.getElementById("fone").value = ""
}
function excluir(){
var idpesquisa = document.getElementById("idcliente").value
fetch(`http://localhost:3000/clientes/${idpesquisa}` , {method: 'DELETE'})
.then(data => data.json())
}
</script>
</body>
</html>