-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.html
126 lines (83 loc) · 3.24 KB
/
edit.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css.css">
<title>Edit single record</title>
</head>
<body>
<h1> Edit Single Record </h1>
<div id="updateee">
</div>
<script type="text/javascript">
idddd = location.search;
if (idddd == "") {
var aaa = prompt("please inter an id")
idddd = "?id=" + aaa;
} else {
idddd = location.search;
}
idddd = idddd.split("=");
idddd = parseInt(idddd[1]);
editrec(idddd);
// Show code
var updatedata = document.getElementById("updateee");
function editrec(valuee) {
valshow = valuee;
tdd = "";
fetch("https://gorest.co.in/public-api/users?id=" + valshow)
.then((data) => {
return data.json()
})
.then((dataa) => {
tdd = `
<input type="text" id="id${dataa.data[0].id}" placeholder="User id" value="${dataa.data[0].id}">
<input type="text" id="n${dataa.data[0].id}" placeholder="name" value="${dataa.data[0].name}">
<input type="text" id="e${dataa.data[0].id}" placeholder="email" value="${dataa.data[0].email}">
<input type="text" id="s${dataa.data[0].id}" placeholder="status" value="${dataa.data[0].status}">
<input type="text" id="g${dataa.data[0].id}" placeholder="genger" value="${dataa.data[0].gender}">
<input type="submit" id="su${dataa.data[0].id}" value="submit update" onclick="update_data(${dataa.data[0].id});">
`
updatedata.innerHTML = tdd;
})
.catch((error) => {
console.log(error);
})
}
function update_data(idupdate) {
console.log(idupdate);
var id = document.getElementById(`id${idupdate}`);
var name = document.getElementById(`n${idupdate}`);
var email = document.getElementById(`e${idupdate}`);
var gender = document.getElementById(`g${idupdate}`);
var status = document.getElementById(`s${idupdate}`);
var dataaa = JSON.stringify({
id: id.value,
name: name.value,
email: email.value,
gender: gender.value,
status: status.value
})
console.log(dataaa)
var urll = `https://gorest.co.in/public-api/users/${idupdate}`;
fetch(urll, {
method: 'PUT',
body: dataaa,
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
})
.then((response) => {
return response.json()
console.log(response.json());
})
.then((json) => {
alert("finel update result : " + json.data.message);
})
.catch((error) => {
alert('update error')
})
}
</script>
</body>
</html>